:root {
    --main-bg: #f0f8ff;
    --primary-color: #ff6b6b;
    --secondary-color: #4ecdc4;
    --text-color: #2d3436;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Fredoka One', cursive;
    background-color: var(--main-bg);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header - Full width at top */
.top-bar {
    width: 100%;
    padding: 10px 20px;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    z-index: 10;
    height: 60px;
    flex-shrink: 0;
    transition: background-color 0.3s;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand .logo {
    height: 40px;
}

.actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.primary-actions,
.secondary-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    padding: 5px 12px;
    border: none;
    border-radius: 50px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    color: white;
    transition: transform 0.1s, filter 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-primary {
    background-color: #0984e3;
}

.btn-secondary {
    background-color: #ff7675;
}

.tool-group {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: 30px;
}

.btn-tool {
    background-color: white;
    color: #2d3436;
    border: 2px solid #dfe6e9;
    padding: 6px 12px;
}

.btn-tool:hover {
    border-color: #74b9ff;
}

.btn-tool.active {
    background-color: #74b9ff;
    border-color: #74b9ff;
    color: white;
}

.pen-thickness {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px 10px;
    border-radius: 20px;
}

.pen-thickness label {
    font-size: 0.75rem;
}

.pen-thickness input[type="range"] {
    width: 70px;
}

.pen-thickness span {
    font-size: 0.8rem;
    min-width: 18px;
}

.palette-toggle {
    display: none;
}

/* Content wrapper below header */
.content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Palette Bar */
.palette-bar {
    background: white;
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
    z-index: 20;
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.palette {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    justify-items: center;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    transform: scale(1.25);
    box-shadow: 0 0 0 2px var(--text-color);
}

.custom-color-picker {
    margin-top: 15px;
    padding: 10px 5px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.custom-color-picker label {
    font-size: 0.7rem;
}

.custom-color-picker input[type="color"] {
    width: 50px;
    height: 50px;
    border: 2px solid #dfe6e9;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
}

.custom-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.custom-color-picker input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.custom-color-picker input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 50%;
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden;
}

canvas {
    display: block;
    touch-action: none;
    cursor: crosshair;
    width: 100%;
    height: 100%;
}

/* Dark Mode */
body.dark-mode {
    --main-bg: #1a1a1a;
    --text-color: #e0e0e0;
}

body.dark-mode .palette-bar,
body.dark-mode .top-bar,
body.dark-mode .modal-content {
    background-color: #2d2d2d;
}

body.dark-mode .workspace {
    background-color: #1a1a1a;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 80%;
    max-width: 900px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: var(--primary-color);
}

.close-btn {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover {
    color: #000;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.image-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.image-btn {
    background: white;
    border: 3px solid transparent;
    border-radius: 15px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    aspect-ratio: 1/1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-btn svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.image-btn:hover {
    transform: translateY(-5px);
    border-color: var(--secondary-color);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

/* Mobile */
@media (max-width: 768px) {
    .palette-toggle {
        display: inline-block;
    }

    .top-bar {
        padding: 4px 8px;
        height: auto;
        min-height: 45px;
        flex-wrap: wrap;
    }

    .brand .logo {
        height: 28px;
    }

    .actions {
        flex-wrap: wrap;
        width: 100%;
        justify-content: center;
        gap: 5px;
    }

    .primary-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 5px;
        border-bottom: 1px solid #eee;
        padding-bottom: 5px;
        margin-bottom: 2px;
    }

    .secondary-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 5px;
    }

    .btn {
        padding: 4px 8px;
        font-size: 0.65rem;
    }

    .btn-tool {
        padding: 5px 9px;
        font-size: 1.1rem;
    }

    .tool-group {
        padding: 3px;
        gap: 2px;
    }

    .pen-thickness {
        padding: 3px 6px;
        gap: 4px;
    }

    .pen-thickness label {
        font-size: 0.65rem;
    }

    .pen-thickness input[type="range"] {
        width: 55px;
    }

    .pen-thickness span {
        font-size: 0.7rem;
    }

    .workspace {
        padding: 8px;
    }

    .palette-bar {
        position: fixed;
        left: 0;
        top: 60px;
        height: calc(100vh - 60px);
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .palette-bar.show {
        transform: translateX(0);
    }

    .image-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .modal-content {
        width: 95%;
        max-height: 85vh;
    }
}

@media (max-width: 400px) {
    .btn {
        padding: 3px 6px;
        font-size: 0.6rem;
    }

    .image-list {
        grid-template-columns: 1fr;
    }
}