/* CSS Variables */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --bg-color: #f9fafb;
    --surface-color: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    flex-wrap: wrap;
    gap: 8px;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-section.brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    height: 32px;
    width: auto;
}

.toolbar-section.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.toolbar-section.tools {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: var(--bg-color);
    border-radius: var(--radius-md);
}

/* Tool Buttons */
.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.tool-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

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

.tool-btn svg {
    width: 20px;
    height: 20px;
}

/* Action Buttons */
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.action-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.action-btn.primary {
    background: var(--primary-color);
    color: white;
}

.action-btn.primary:hover {
    background: var(--primary-hover);
}

.action-btn svg {
    width: 18px;
    height: 18px;
}

/* Color Picker */
.color-picker-wrapper {
    position: relative;
    width: 36px;
    height: 36px;
}

.color-picker-wrapper input[type="color"] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.color-preview {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-color);
    background: #000000;
    pointer-events: none;
}

/* Size Control */
.size-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
}

.size-control label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.size-control input[type="range"] {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 2px;
    cursor: pointer;
}

.size-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.size-control #sizeValue {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 20px;
}

/* Quick Colors */
.quick-colors {
    display: flex;
    gap: 4px;
}

.color-btn {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.color-btn:hover {
    transform: scale(1.1);
    border-color: var(--text-secondary);
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-primary);
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

/* Mobile Toolbar */
.mobile-toolbar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 99;
    padding: 16px;
}

.mobile-toolbar.active {
    display: block;
}

.mobile-tool-section {
    margin-bottom: 16px;
}

.mobile-tool-section h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-tools-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.mobile-tools-grid .tool-btn {
    width: 100%;
    height: auto;
    flex-direction: column;
    padding: 12px 8px;
    gap: 4px;
}

.mobile-tools-grid .tool-btn span {
    font-size: 0.75rem;
}

.mobile-color-size {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mobile-color-size input[type="color"] {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.mobile-quick-colors {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mobile-quick-colors .color-btn {
    width: 32px;
    height: 32px;
}

.mobile-size-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mobile-size-control label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.mobile-size-control input[type="range"] {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 4px;
}

.mobile-size-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
}

.mobile-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.mobile-actions .action-btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--radius-md);
}

.mobile-actions .action-btn.primary {
    grid-column: span 2;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-color);
}

.canvas-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#drawingCanvas {
    background: white;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    cursor: crosshair;
    touch-action: none;
}

/* Canvas Options */
.canvas-options {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 50;
}

.option-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.option-btn:hover {
    background: var(--bg-color);
}

.option-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.bg-options-panel {
    display: none;
    position: absolute;
    top: 48px;
    right: 0;
    width: 240px;
    padding: 16px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.bg-options-panel.active {
    display: block;
}

.bg-options-panel h4 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.bg-options-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.bg-option {
    width: 100%;
    aspect-ratio: 1;
    padding: 4px;
    background: transparent;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.bg-option:hover {
    border-color: var(--primary-color);
}

.bg-option.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.bg-option span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 2px;
}

.grid-pattern {
    background-image:
        linear-gradient(to right, #e5e7eb 1px, transparent 1px),
        linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
    background-size: 8px 8px;
    background-color: white;
}

.dots-pattern {
    background-image: radial-gradient(circle, #d1d5db 1px, transparent 1px);
    background-size: 8px 8px;
    background-color: white;
}

.lines-pattern {
    background-image: linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
    background-size: 100% 8px;
    background-color: white;
}

.custom-bg {
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-bg label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.custom-bg input[type="color"] {
    width: 40px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    z-index: 50;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
}

.zoom-btn:hover {
    background: var(--bg-color);
    color: var(--text-primary);
}

.zoom-level {
    padding: 0 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    font-size: 1.25rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Text Modal */
#textInput {
    width: 100%;
    height: 100px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    resize: vertical;
    margin-bottom: 12px;
}

#textInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.text-options {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.text-options select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--surface-color);
    cursor: pointer;
}

.text-options select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.text-style-btns {
    display: flex;
    gap: 4px;
}

.style-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.style-btn:hover {
    background: var(--bg-color);
}

.style-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Export Modal */
.export-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.export-option {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.export-option label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.export-option select,
.export-option input[type="text"] {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.export-option select:focus,
.export-option input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.export-option input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 3px;
}

.export-option input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

/* Modal Actions */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn.secondary {
    background: var(--bg-color);
    color: var(--text-secondary);
}

.btn.secondary:hover {
    background: var(--border-color);
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

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

/* Footer */
.footer {
    padding: 12px 16px;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    text-align: center;
    z-index: 100;
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .toolbar-section.tools {
        display: none;
    }

    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .toolbar {
        padding: 8px 12px;
    }

    .toolbar-section.brand h1 {
        font-size: 1rem;
    }

    .toolbar-section.actions {
        display: none;
    }

    .canvas-wrapper {
        padding: 10px;
    }

    .zoom-controls {
        bottom: 8px;
        left: 8px;
    }

    .canvas-options {
        top: 8px;
        right: 8px;
    }

    .bg-options-panel {
        width: calc(100vw - 32px);
        right: -8px;
    }
}

@media (max-width: 480px) {
    .mobile-tools-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .modal-content {
        padding: 16px;
    }

    .text-options {
        flex-direction: column;
    }

    .text-options select {
        width: 100%;
    }
}

/* Dark mode canvas background text color adjustment */
.canvas-wrapper[data-bg="dark"] #drawingCanvas {
    background: #1f2937;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .tool-btn, .action-btn, .option-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .color-btn {
        width: 32px;
        height: 32px;
    }
}

/* Utility classes for canvas backgrounds */
.canvas-bg-white { background-color: #ffffff; }
.canvas-bg-light-gray { background-color: #f3f4f6; }
.canvas-bg-cream { background-color: #fef3c7; }
.canvas-bg-light-blue { background-color: #dbeafe; }
.canvas-bg-dark { background-color: #1f2937; }

.canvas-bg-grid {
    background-color: #ffffff;
    background-image:
        linear-gradient(to right, #e5e7eb 1px, transparent 1px),
        linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
    background-size: 20px 20px;
}

.canvas-bg-dots {
    background-color: #ffffff;
    background-image: radial-gradient(circle, #d1d5db 1px, transparent 1px);
    background-size: 20px 20px;
}

.canvas-bg-lines {
    background-color: #ffffff;
    background-image: linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
    background-size: 100% 24px;
}
