:root {
    font-family: Arial, Helvetica, sans-serif;
    color: #502d3c;
    background: #ffeef6;
    --app-bg: #ffeef6;
    --panel-bg: #ffdae8;
    --button-bg: #fff4f9;
    --button-hover: #ffe5f0;
    --active-bg: #ffa8c9;
    --border: #e696b4;
    --section-text: #784155;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(#fff7fb, #ffdeec);
}

button,
input,
select {
    font: inherit;
}

button {
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #502d3c;
    background: linear-gradient(#fffafd, var(--button-bg));
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.9), 0 2px 5px rgba(90, 35, 65, 0.13);
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--button-hover);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(230, 105, 155, 0.32);
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

.home-header {
    padding: 22px 28px 20px;
    background: linear-gradient(#fff4fa, #ffc7de);
    border-bottom: 1px solid rgba(230, 150, 180, 0.7);
}

.home-header h1 {
    margin: 0;
    font-size: 28px;
}

.home-header p {
    margin: 5px 0 0;
    color: #784155;
    font-size: 14px;
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 190px);
    align-content: start;
    gap: 18px;
    min-height: calc(100vh - 100px);
    padding: 24px;
}

.project-card {
    position: relative;
    display: flex;
    width: 190px;
    height: 190px;
    padding: 10px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: linear-gradient(#fffafd, #ffe5f0);
    box-shadow: 5px 7px 12px rgba(90, 35, 65, 0.16), inset 0 1px rgba(255, 255, 255, 0.9);
    color: #502d3c;
    font-weight: 700;
    cursor: pointer;
}

.project-card:hover {
    transform: translateY(-2px);
    background: #ffe5f0;
}

.new-card {
    border: 2px dashed var(--border);
    font-size: 16px;
}

.new-card strong {
    font-size: 42px;
    line-height: 1;
}

.project-card img {
    width: 150px;
    height: 125px;
    object-fit: contain;
    border: 1px solid rgba(230, 150, 180, 0.7);
    background-color: white;
    background-image:
        linear-gradient(45deg, #ddd 25%, transparent 25%),
        linear-gradient(-45deg, #ddd 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ddd 75%),
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
    background-size: 12px 12px;
}

.card-menu {
    position: absolute;
    top: 7px;
    right: 7px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    border-radius: 50%;
}

.glossy-panel {
    background: linear-gradient(#ffedf6, #ffcfe1);
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.85);
}

.editor-view {
    height: 100vh;
    overflow: hidden;
    background: var(--app-bg);
}

.top-toolbar {
    display: flex;
    min-height: 53px;
    padding: 8px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

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

.tool-button.active {
    background: var(--active-bg);
    box-shadow: inset 0 2px 5px rgba(120, 50, 80, 0.16);
}

.color-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

#colorSwatch {
    width: 19px;
    height: 19px;
    border: 1px solid #502d3c;
    border-radius: 4px;
    background: #000000;
}

.editor-body {
    display: grid;
    grid-template-columns: 160px minmax(300px, 1fr) 300px;
    height: calc(100vh - 53px);
}

.side-panel,
.layer-panel {
    padding: 12px 10px;
    overflow-y: auto;
}

.side-panel {
    border-right: 1px solid var(--border);
}

.layer-panel {
    border-left: 1px solid var(--border);
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 18px;
}

.panel-section h2,
.layer-heading h2,
.app-dialog h2 {
    margin: 0;
    color: var(--section-text);
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.panel-section label {
    font-size: 13px;
    font-weight: 700;
}

input[type="range"] {
    width: 100%;
    accent-color: #df6598;
}

.side-button {
    width: 100%;
    text-align: left;
}

.canvas-holder {
    display: grid;
    place-items: center;
    padding: 18px;
    overflow: auto;
    background: linear-gradient(#ffe1ee, #fabcD7);
}

.canvas-frame {
    position: relative;
    width: min(512px, 100%);
    aspect-ratio: 1;
    flex: 0 0 auto;
    border: 3px solid rgba(120, 65, 85, 0.3);
    box-shadow: 0 8px 22px rgba(90, 35, 65, 0.22);
    background-color: white;
    background-image:
        linear-gradient(45deg, #f5f5f5 25%, transparent 25%),
        linear-gradient(-45deg, #f5f5f5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #cdcdcd 75%),
        linear-gradient(-45deg, transparent 75%, #cdcdcd 75%);
    background-position: 0 0, 0 12px, 12px -12px, -12px 0;
    background-size: 24px 24px;
}

#drawingCanvas,
#overlayCanvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

#drawingCanvas {
    pointer-events: none;
}

#overlayCanvas {
    cursor: crosshair;
    touch-action: none;
}

.layer-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.small-button {
    min-width: 34px;
    padding: 4px 9px;
}

.layer-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.layer-row {
    display: grid;
    grid-template-columns: 32px 46px minmax(0, 1fr);
    gap: 6px;
    align-items: center;
    padding: 5px;
    border: 1px solid transparent;
    border-radius: 8px;
}

.layer-row.active {
    border-color: var(--border);
    background: rgba(255, 168, 201, 0.45);
}

.layer-row canvas {
    width: 46px;
    height: 36px;
    border: 1px solid var(--border);
    background: white;
    image-rendering: pixelated;
}

.layer-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.layer-controls {
    grid-column: 1 / -1;
    display: flex;
    gap: 5px;
}

.layer-controls button {
    min-width: 30px;
    min-height: 28px;
    padding: 3px 7px;
    font-size: 12px;
}

.layer-opacity {
    flex: 1;
    min-width: 70px;
}

.app-dialog {
    width: min(390px, calc(100% - 30px));
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: #502d3c;
    background: #fff7fb;
    box-shadow: 0 20px 60px rgba(80, 45, 60, 0.25);
}

.app-dialog::backdrop {
    background: rgba(80, 45, 60, 0.35);
}

.app-dialog form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#customColorInput {
    width: 100%;
    height: 70px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.palette-color {
    min-width: 0;
    min-height: 30px;
    padding: 0;
}

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

@media (max-width: 900px) {
    .editor-view {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .top-toolbar {
        flex-wrap: wrap;
    }

    .editor-body {
        grid-template-columns: 145px minmax(280px, 1fr);
        height: auto;
    }

    .canvas-holder {
        min-height: 600px;
    }

    .layer-panel {
        grid-column: 1 / -1;
        min-height: 210px;
        border-top: 1px solid var(--border);
        border-left: 0;
    }
}

@media (max-width: 580px) {
    .top-toolbar,
    .toolbar-group {
        align-items: stretch;
    }

    .toolbar-group {
        flex-wrap: wrap;
    }

    .editor-body {
        display: flex;
        flex-direction: column;
    }

    .side-panel {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .canvas-holder {
        min-height: 360px;
        padding: 10px;
    }

    .project-grid {
        justify-content: center;
    }
}
