/* Paint & Color - Kids Coloring App */
/* Mobile-first design for 320px base */

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

:root {
    /* UI Colors */
    --color-header: #6C5CE7;
    --color-header-text: #FFFFFF;
    --color-bg: #F8F9FA;
    --color-palette-bg: #FFFFFF;
    --color-active: #00CEC9;
    --color-stroke: #2D3436;

    /* Palette Colors */
    --color-red: #FF6B6B;
    --color-orange: #FFA500;
    --color-yellow: #FFE66D;
    --color-green: #4ECDC4;
    --color-blue: #45B7D1;
    --color-purple: #A855F7;
    --color-pink: #FF69B4;
    --color-brown: #8B4513;
    --color-black: #2D3436;
    --color-white: #FFFFFF;
    --color-gray: #95A5A6;

    /* Sizes */
    --header-height: 56px;
    --palette-height: 120px;
    --color-btn-size: 44px;
    --transition-speed: 0.2s;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--color-bg);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* App Container */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
    height: var(--header-height);
    background: var(--color-header);
    color: var(--color-header-text);
    flex-shrink: 0;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title::before {
    content: '🎨';
}

.header-actions {
    display: flex;
    gap: 4px;
}

.header-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--color-header-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-speed);
    -webkit-tap-highlight-color: transparent;
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.4);
}

/* Drawing Area */
.drawing-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--color-bg);
    overflow: hidden;
}

.drawing-svg {
    display: none;
    width: 100%;
    max-width: 320px;
    max-height: calc(100vh - var(--header-height) - var(--palette-height) - 40px);
    aspect-ratio: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.drawing-svg.active {
    display: block;
}

/* SVG Regions - Make clickable areas obvious */
.drawing-svg [data-region] {
    cursor: pointer;
    transition: fill var(--transition-speed);
}

.drawing-svg [data-region]:hover {
    filter: brightness(0.95);
}

/* Color Palette */
.palette {
    background: var(--color-palette-bg);
    padding: 12px 16px;
    border-top: 1px solid #E0E0E0;
    flex-shrink: 0;
}

.palette-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.palette-row:last-child {
    margin-bottom: 0;
}

.color-btn {
    width: var(--color-btn-size);
    height: var(--color-btn-size);
    border: 3px solid #E0E0E0;
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-speed), border-color var(--transition-speed);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.color-btn:active {
    transform: scale(0.9);
}

.color-btn.active {
    border-color: var(--color-active);
    box-shadow: 0 0 0 3px rgba(0, 206, 201, 0.3);
    transform: scale(1.1);
}

/* White color needs visible border */
.color-btn[data-color="#FFFFFF"] {
    border-color: #CCC;
}

.color-btn[data-color="#FFFFFF"].active {
    border-color: var(--color-active);
}

/* Eraser button */
.color-btn.eraser {
    background: linear-gradient(135deg, #FFF 50%, #EEE 50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal.open {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 340px;
    max-height: 80vh;
    overflow: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #E0E0E0;
}

.modal-header h2 {
    font-size: 1.125rem;
    color: var(--color-stroke);
}

.close-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
}

.close-btn:active {
    background: #F0F0F0;
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 20px;
}

.gallery-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border: 2px solid #E0E0E0;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: border-color var(--transition-speed), background var(--transition-speed);
    -webkit-tap-highlight-color: transparent;
}

.gallery-item:active {
    background: #F8F9FA;
}

.gallery-item.active {
    border-color: var(--color-active);
    background: rgba(0, 206, 201, 0.1);
}

.gallery-icon {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 8px;
}

.gallery-label {
    font-size: 0.875rem;
    color: var(--color-stroke);
    font-weight: 500;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-stroke);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.875rem;
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    z-index: 200;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Tablet and Desktop */
@media (min-width: 768px) {
    :root {
        --color-btn-size: 52px;
    }

    .drawing-svg {
        max-width: 400px;
    }

    .palette-row {
        gap: 12px;
    }

    .gallery-grid {
        gap: 16px;
    }

    .gallery-icon {
        font-size: 4rem;
    }
}

/* Landscape orientation */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --header-height: 48px;
        --palette-height: 80px;
        --color-btn-size: 36px;
    }

    .header-title {
        font-size: 1rem;
    }

    .palette {
        padding: 8px 16px;
    }

    .palette-row {
        gap: 6px;
        margin-bottom: 4px;
    }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(0px, env(safe-area-inset-top));
        height: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
    }

    .palette {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* Animation for color fill */
@keyframes colorPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

.drawing-svg [data-region].just-colored {
    animation: colorPop 0.2s ease-out;
}

/* Prevent text selection on touch devices */
.app * {
    -webkit-touch-callout: none;
}
