:root {
    font-family: "Pixelify Sans", "Courier New", monospace;
    font-weight: 500;
    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;
    color: #502d3c;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

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

.project-grid.empty {
    grid-template-columns: 190px minmax(280px, 360px);
    align-items: center;
    justify-content: center;
    gap: 30px;
}

.empty-state {
    display: flex;
    min-width: 0;
    align-items: center;
}

.empty-state-message {
    max-width: 360px;
}

.empty-state-message h2 {
    margin: 0 0 8px;
    color: var(--section-text);
    font-size: 22px;
}

.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;
}

.toolbar-divider {
    width: 1px;
    height: 27px;
    margin: 0 2px;
    background: rgba(166, 79, 116, 0.25);
}

.document-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.document-action svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}

.zoom-controls button {
    min-width: 36px;
    padding-inline: 8px;
    font-size: 20px;
    line-height: 1;
}

#zoomValue {
    min-width: 52px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
}

#colorSwatch {
    width: 34px;
    height: 34px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #000000;
    box-shadow: 0 0 0 1px #9c4d70, 0 2px 5px rgba(80, 45, 60, 0.2);
}

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

.side-panel,
.layer-panel {
    overflow-y: auto;
}

.side-panel {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    padding: 0;
    border-right: 1px solid var(--border);
}

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

.tool-rail {
    display: flex;
    min-height: 100%;
    padding: 10px 8px;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
    border-right: 1px solid rgba(166, 79, 116, 0.24);
    background: rgba(255, 247, 251, 0.5);
}

.tool-rail-main,
.tool-rail-footer {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.tool-button,
.tool-color-button {
    display: flex;
    width: 55px;
    min-height: 55px;
    padding: 5px 3px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-color: transparent;
    border-radius: 11px;
    background: transparent;
    box-shadow: none;
    color: #6d3b51;
}

.tool-button:hover:not(:disabled),
.tool-color-button:hover:not(:disabled) {
    border-color: rgba(198, 84, 132, 0.4);
    background: rgba(255, 255, 255, 0.65);
}

.tool-button.active {
    color: #ffffff;
    border-color: #a93d6c;
    background: linear-gradient(#df6c9d, #c64f82);
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 3px 7px rgba(119, 41, 75, 0.24);
}

.tool-button svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tool-button span,
.tool-color-button > span:last-child {
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

.tool-button.utility-tool {
    border-top: 1px solid rgba(166, 79, 116, 0.2);
    border-radius: 0 0 11px 11px;
}

.tool-color-button {
    min-height: 65px;
}

.tool-settings {
    min-width: 0;
    padding: 16px 14px;
    background: rgba(255, 239, 247, 0.4);
}

.tool-settings-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tool-settings-heading {
    display: flex;
    margin-bottom: 5px;
    align-items: center;
    gap: 9px;
}

.settings-tool-icon {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid rgba(198, 84, 132, 0.35);
    border-radius: 9px;
    color: #a13e6a;
    background: rgba(255, 255, 255, 0.65);
}

.settings-tool-icon svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

.tool-settings-section label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
}

.tool-settings-section output {
    min-width: 42px;
    padding: 2px 5px;
    border-radius: 5px;
    color: #8c3f61;
    background: rgba(255, 255, 255, 0.62);
    font-size: 11px;
    text-align: center;
}

.brush-type-picker {
    position: relative;
}

.brush-type-picker summary {
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 2px 5px rgba(90, 35, 65, 0.1);
    cursor: pointer;
    list-style-position: inside;
}

.brush-type-picker[open] summary {
    border-radius: 7px 7px 0 0;
}

.brush-type-list {
    display: grid;
    max-height: 330px;
    padding: 5px;
    gap: 5px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 7px 7px;
    background: #fff4f9;
}

.brush-type-option {
    display: grid;
    min-height: 56px;
    padding: 6px;
    gap: 5px;
    border-color: transparent;
    background: rgba(255, 255, 255, 0.55);
    box-shadow: none;
    text-align: left;
}

.brush-type-option:hover:not(:disabled) {
    border-color: var(--border);
    background: #ffffff;
}

.brush-type-option.active {
    border-color: #b64576;
    background: #ffd5e6;
}

.brush-type-option > span:first-child {
    font-size: 11px;
    font-weight: 700;
}

.dither-preview {
    display: block;
    width: 100%;
    height: 24px;
    border: 1px solid rgba(80, 45, 60, 0.28);
    border-radius: 3px;
    background-color: #ffffff;
    image-rendering: pixelated;
}

.dither-preview.solid {
    background: #713c54;
}

.dither-preview.dither-0 {
    background-image: conic-gradient(#713c54 25%, #ffffff 0 50%, #713c54 0 75%, #ffffff 0);
    background-size: 4px 4px;
}

.dither-preview.dither-1 {
    background-image: radial-gradient(circle at 1px 1px, #713c54 1px, transparent 1.2px);
    background-size: 4px 4px;
}

.dither-preview.dither-1b {
    background-image: radial-gradient(circle at 3px 3px, #713c54 1px, transparent 1.2px);
    background-size: 4px 4px;
}

.dither-preview.dither-2 {
    background-image:
        radial-gradient(circle at 1px 1px, #713c54 1px, transparent 1.2px),
        radial-gradient(circle at 5px 5px, #713c54 1px, transparent 1.2px);
    background-size: 8px 8px;
}

.dither-preview.dither-3 {
    background-image: radial-gradient(circle at 1px 1px, #713c54 1px, transparent 1.2px);
    background-size: 8px 8px;
}

.dither-preview.dither-4 {
    background-image: repeating-linear-gradient(
        135deg,
        transparent 0 3px,
        #713c54 3px 4px,
        transparent 4px 7px
    );
}

.dither-preview.dither-5 {
    background-image:
        repeating-linear-gradient(0deg, transparent 0 3px, #713c54 3px 4px),
        repeating-linear-gradient(90deg, transparent 0 3px, #713c54 3px 4px);
    background-size: 8px 8px;
}

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

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

.canvas-frame {
    position: relative;
    width: 512px;
    height: 512px;
    margin: auto;
    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;
}

.canvas-frame.drag-over {
    border-color: transparent;
    box-shadow: 0 8px 22px rgba(90, 35, 65, 0.22);
}

.canvas-frame.drag-over canvas {
    opacity: 0.3;
}

.canvas-frame.drag-over::before {
    content: "Drop image here";
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 50%;
    padding: 14px 20px;
    border: 1px solid rgba(223, 49, 91, 0.45);
    border-radius: 10px;
    color: #8b183d;
    background: rgba(255, 247, 251, 0.92);
    box-shadow: 0 5px 18px rgba(90, 35, 65, 0.18);
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.canvas-frame.drag-over::after {
    content: "";
    position: absolute;
    z-index: 3;
    inset: -7px;
    border-radius: 5px;
    background:
        repeating-linear-gradient(90deg, #df315b 0 12px, transparent 12px 22px) 0 0 / 44px 4px repeat-x,
        repeating-linear-gradient(180deg, #df315b 0 12px, transparent 12px 22px) 100% 0 / 4px 44px repeat-y,
        repeating-linear-gradient(270deg, #df315b 0 12px, transparent 12px 22px) 100% 100% / 44px 4px repeat-x,
        repeating-linear-gradient(0deg, #df315b 0 12px, transparent 12px 22px) 0 100% / 4px 44px repeat-y;
    pointer-events: none;
    animation: marching-dashes 0.65s linear infinite;
}

@keyframes marching-dashes {
    to {
        background-position:
            44px 0,
            100% 44px,
            calc(100% - 44px) 100%,
            0 calc(100% - 44px);
    }
}

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

#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: 20px 32px 46px minmax(0, 1fr);
    gap: 6px;
    align-items: center;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 247, 251, 0.72);
    box-shadow: 0 2px 5px rgba(90, 35, 65, 0.1);
}

.layer-row:nth-child(even) {
    background: rgba(255, 231, 241, 0.78);
}

.layer-row.active {
    border-color: #c75486;
    border-width: 2px;
    padding: 4px;
    background: rgba(255, 168, 201, 0.45);
    box-shadow: 0 2px 7px rgba(122, 40, 79, 0.2);
}

.layer-preview {
    display: flex;
    width: 46px;
    height: 36px;
    align-items: center;
    justify-content: flex-start;
}

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

.clipping-indicator {
    display: grid;
    width: 20px;
    height: 36px;
    place-items: center;
    color: #9b3e68;
    pointer-events: none;
}

.clipping-indicator svg {
    width: 17px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.visibility-button {
    display: grid;
    min-width: 32px;
    padding: 4px;
    place-items: center;
}

.visibility-button svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

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

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

.layer-controls .layer-action-button {
    display: grid;
    width: 32px;
    padding: 4px;
    place-items: center;
}

.layer-controls .layer-action-button.active {
    color: #ffffff;
    border-color: #a13e6a;
    background: #c75486;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.layer-action-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.layer-controls .layer-action-button.danger-button {
    color: #ffffff;
}

.layer-opacity {
    flex: 1;
    flex-basis: 100%;
    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;
}

.project-menu-actions {
    display: grid;
    gap: 8px;
}

.project-menu-actions button {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 9px;
    text-align: left;
}

.button-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.danger-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    border-color: #a8173e;
    background: linear-gradient(#df315b, #bd1743);
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.25), 0 2px 5px rgba(120, 20, 55, 0.25);
}

.danger-button:hover:not(:disabled) {
    color: #ffffff;
    background: #a8173e;
}

.app-dialog p {
    margin: 0;
    line-height: 1.45;
}

.context-menu {
    position: fixed;
    z-index: 20;
    min-width: 150px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff7fb;
    box-shadow: 0 8px 24px rgba(80, 45, 60, 0.24);
}

.context-menu button {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 9px;
    border-color: transparent;
    box-shadow: none;
    text-align: left;
}

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

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

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

    .side-panel {
        grid-template-columns: 64px minmax(0, 1fr);
    }

    .tool-rail {
        padding-inline: 4px;
    }

    .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: block;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .tool-rail {
        min-height: 0;
        padding: 7px;
        flex-direction: row;
        align-items: center;
        border-right: 0;
        border-bottom: 1px solid rgba(166, 79, 116, 0.24);
        overflow-x: auto;
    }

    .tool-rail-main,
    .tool-rail-footer {
        flex-direction: row;
    }

    .tool-rail-footer {
        margin-left: auto;
    }

    .tool-button,
    .tool-color-button {
        width: 52px;
        min-width: 52px;
        min-height: 50px;
    }

    .tool-button.utility-tool {
        border-top: 0;
        border-left: 1px solid rgba(166, 79, 116, 0.2);
        border-radius: 0 11px 11px 0;
    }

    .tool-color-button {
        min-height: 55px;
    }

    #colorSwatch {
        width: 28px;
        height: 28px;
    }

    .tool-settings {
        min-height: 150px;
        padding: 12px 14px;
    }

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

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

    .project-grid.empty {
        display: flex;
        flex-direction: column;
        gap: 24px;
    }

    .empty-state {
        flex-direction: column;
        text-align: center;
    }

}
