/* ColoringYes — Editor Styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --purple: #7c3aed; --purple-lt: #9d5cf5;
    --purple-pale: #f5f0ff; --bg: #e8e4f5;
}
html, body {
    height: 100%; overflow: hidden;
    background: var(--bg); font-family: 'Nunito', sans-serif;
    touch-action: none; user-select: none;
}

/* ── Accessibility: Focus Styles ── */
:focus-visible {
    outline: 2px solid var(--purple);
    outline-offset: 2px;
}
button:focus-visible, a:focus-visible {
    outline: 2px solid var(--purple);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.25);
}

/* ── TOP BAR ── */
#cy-topbar {
    position: fixed; top: 0; left: 0; right: 0; height: 56px;
    background: #fff; display: flex; align-items: center;
    justify-content: space-between; padding: 0 12px; gap: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08); z-index: 100;
}
.cy-back {
    display: flex; align-items: center; gap: 5px;
    color: var(--purple); font-weight: 700; font-size: 14px;
    text-decoration: none; white-space: nowrap; flex-shrink: 0;
}
.cy-back svg { width: 18px; height: 18px; }
#cy-title {
    font-size: 13px; font-weight: 700; color: #333;
    text-align: center; flex: 1; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.cy-top-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.cy-icon-btn {
    width: 38px; height: 38px; border-radius: 10px; border: none;
    background: var(--purple-pale); color: var(--purple);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .1s;
}
.cy-icon-btn:hover { background: #ede9ff; transform: scale(1.05); }
.cy-icon-btn svg { width: 18px; height: 18px; }
.cy-save-btn {
    display: flex; align-items: center; gap: 5px;
    background: linear-gradient(135deg, var(--purple), var(--purple-lt));
    color: #fff; border: none; border-radius: 10px;
    padding: 0 14px; height: 38px;
    font-family: 'Nunito', sans-serif; font-size: 14px; font-weight: 700;
    cursor: pointer; white-space: nowrap;
    transition: filter .15s;
}
.cy-save-btn:hover { filter: brightness(1.08); }
.cy-save-btn svg { width: 16px; height: 16px; }

/* ── CANVAS AREA ── */
#cy-canvas-area {
    position: fixed; top: 56px; left: 0; right: 0; bottom: 130px;
    overflow: hidden; display: flex; align-items: center; justify-content: center;
    background: var(--bg);
    background-image: radial-gradient(#c4b5fd44 1px, transparent 1px);
    background-size: 22px 22px;
}
#cy-wrap {
    position: relative; transform-origin: center center; cursor: crosshair;
}
#cy-wrap.move   { cursor: grab; }
#cy-wrap.moving { cursor: grabbing; }
#cy-wrap.eraser { cursor: cell; }

/*
 * LAYER STACK (bottom to top):
 * 1. #cy-color  — white background + all user drawing (source-over)
 * 2. #cy-lines  — original image with multiply blend → lines appear on top of colors
 * 3. #cy-events — transparent, captures pointer events
 */
#cy-color { display: block; border-radius: 4px; box-shadow: 0 8px 40px rgba(0,0,0,0.2); }
#cy-lines  { position: absolute; top: 0; left: 0; pointer-events: none; mix-blend-mode: multiply; }
#cy-events { position: absolute; top: 0; left: 0; opacity: 0; }

/* ── COLOR BAR ── */
#cy-color-bar {
    position: fixed; bottom: 70px; left: 0; right: 0; height: 60px;
    background: #fff; display: flex; align-items: center;
    padding: 0 10px; gap: 8px; overflow-x: auto; scrollbar-width: none;
    box-shadow: 0 -1px 0 #e8e4ff; z-index: 90;
}
#cy-color-bar::-webkit-scrollbar { display: none; }
.sw {
    width: 38px; height: 38px; border-radius: 50%;
    border: 3px solid transparent; cursor: pointer; flex-shrink: 0;
    transition: transform .15s, border-color .15s, box-shadow .15s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
.sw:hover { transform: scale(1.15); }
.sw.active { border-color: #222; transform: scale(1.22); box-shadow: 0 3px 12px rgba(0,0,0,0.3); }
#cy-wheel {
    width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
    border: 3px solid #ccc; cursor: pointer; padding: 0;
    background: conic-gradient(red,yellow,lime,cyan,blue,magenta,red);
    transition: transform .15s;
}
#cy-wheel:hover { transform: scale(1.15); }
#cy-color-pick { position: absolute; opacity: 0; width: 0; height: 0; }

/* ── TOOLBAR ── */
#cy-toolbar {
    position: fixed; bottom: 0; left: 0; right: 0; height: 70px;
    background: #fff; display: flex; align-items: center;
    justify-content: space-around; padding: 0 4px;
    border-top: 2px solid #f0eef8; z-index: 90;
}
.cy-t {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; cursor: pointer;
    padding: 6px 8px; border-radius: 12px;
    color: #aaa; font-family: 'Nunito', sans-serif;
    font-size: 10px; font-weight: 700; min-width: 48px;
    transition: background .15s, color .15s;
}
.cy-t svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.cy-t:hover { background: var(--purple-pale); color: var(--purple); }
.cy-t.on { background: var(--purple-pale); color: var(--purple); }

/* ── SIZE PANEL ── */
#cy-size-panel {
    position: fixed; bottom: 205px; left: 50%; transform: translateX(-50%);
    background: #fff; border-radius: 14px; padding: 16px 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15); z-index: 200;
    display: none; min-width: 240px;
}
#cy-size-panel.open { display: block; }
#cy-size-panel label {
    display: flex; justify-content: space-between;
    font-weight: 700; font-size: 13px; color: #555; margin-bottom: 10px;
}
#cy-sz-slider { width: 100%; accent-color: var(--purple); }

/* ── BRUSH CURSOR ── */
#cy-dot {
    position: fixed; border-radius: 50%; pointer-events: none;
    transform: translate(-50%,-50%); z-index: 500;
    border: 1.5px solid rgba(0,0,0,0.35); display: none;
    transition: width .1s, height .1s;
}

/* ── TOAST ── */
#cy-toast {
    position: fixed; bottom: 160px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1a1a2e; color: #fff;
    padding: 10px 20px; border-radius: 30px;
    font-size: 14px; font-weight: 600;
    opacity: 0; transition: opacity .3s, transform .3s;
    pointer-events: none; z-index: 300; white-space: nowrap;
}
#cy-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── LOADING ── */
#cy-loading {
    position: fixed; inset: 0; background: var(--bg);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; z-index: 999; gap: 16px;
}
.cy-spin {
    width: 48px; height: 48px; border: 4px solid #e8e4ff;
    border-top-color: var(--purple); border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#cy-loading p { font-weight: 700; color: var(--purple); font-size: 16px; }

@media (max-width: 480px) {
    .cy-t { min-width: 40px; padding: 5px 3px; font-size: 9px; }
    .cy-save-btn span { display: none; }
}
