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

:root {
    --bg: #0d0d1a;
    --bg-secondary: #151528;
    --bg-tertiary: #1c1c35;
    --border: rgba(255,255,255,0.08);
    --text: #c8d0e0;
    --text-muted: #6a7090;
    --accent: #e94560;
    --accent-hover: #ff5a75;
    --radius: 8px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    height: 100vh;
    overflow: hidden;
}

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

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

nav {
    display: flex;
    gap: 4px;
}

.nav-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.nav-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.15); }
.nav-btn.active { background: var(--bg-tertiary); color: var(--text); border-color: var(--accent); }

/* Views */
.view { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.view.active { display: flex; }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tool-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.tool-btn:hover { border-color: rgba(255,255,255,0.2); }
.tool-btn.active { border-color: var(--accent); background: rgba(233,69,96,0.15); }

/* Brush size */
input[type="range"] {
    width: 80px;
    accent-color: var(--accent);
}

.size-display {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 20px;
    text-align: center;
    font-family: monospace;
}

/* Colors */
.colors {
    gap: 4px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--accent); transform: scale(1.15); }
.color-swatch[data-color="#ffffff"] { border: 2px solid rgba(255,255,255,0.2); }
.color-swatch[data-color="#ffffff"].active { border-color: var(--accent); }

/* Color picker button */
.color-picker-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    position: relative;
    transition: border-color 0.15s, transform 0.1s;
    font-size: 1.1rem;
    overflow: hidden;
}

.color-picker-btn:hover {
    border-color: rgba(255,255,255,0.3);
    transform: scale(1.15);
}

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

/* Action buttons */
.action-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.action-btn:hover { border-color: rgba(255,255,255,0.2); }
.action-btn.save { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.action-btn.save:hover { background: var(--accent-hover); }

.actions { margin-left: auto; }

/* Canvas */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: hidden;
    background: var(--bg);
}

#paint-canvas {
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    cursor: crosshair;
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
}

/* Gallery */
#gallery-view {
    overflow-y: auto;
    padding: 20px;
}

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

.gallery-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}

.gallery-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.gallery-card img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    background: white;
    display: block;
}

.gallery-card-info {
    padding: 10px 12px;
}

.gallery-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-card-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Create card */
.create-card {
    border-style: dashed;
    border-color: rgba(255,255,255,0.12);
}

.create-card:hover {
    border-color: var(--accent);
    background: rgba(233,69,96,0.05);
}

.create-card-canvas {
    width: 100%;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
}

.create-icon {
    font-size: 3rem;
    opacity: 0.6;
    transition: opacity 0.15s, transform 0.15s;
}

.create-card:hover .create-icon {
    opacity: 1;
    transform: scale(1.1);
}

.gallery-loading, .gallery-empty {
    text-align: center;
    padding: 60px 20px;
    grid-column: 1 / -1;
}

.gallery-empty .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.gallery-empty h2 { margin-bottom: 6px; }
.gallery-empty p { color: var(--text-muted); }

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.lightbox-content {
    max-width: 90vw;
    max-height: 90vh;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-close {
    position: absolute;
    top: -12px;
    right: -12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox img {
    max-width: 100%;
    max-height: 75vh;
    border-radius: 4px;
    background: white;
}

.lightbox-info {
    margin-top: 12px;
    text-align: center;
}

.lightbox-info h3 { font-size: 1.1rem; margin-bottom: 4px; }
.lightbox-info p { color: var(--text-muted); font-size: 0.85rem; }



/* Save Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
}

.modal-content h2 {
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-preview {
    margin: 16px 0;
    text-align: center;
}

.modal-preview canvas {
    max-width: 100%;
    max-height: 180px;
    border-radius: 4px;
    background: white;
}

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

/* Mobile */
@media (max-width: 640px) {
    .toolbar {
        gap: 8px;
        padding: 8px 10px;
    }

    .tool-group.colors {
        order: 10;
        flex-wrap: wrap;
    }

    .actions { margin-left: 0; }

    #paint-canvas {
        max-width: calc(100vw - 32px);
    }

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