/* Coloringoo Online Coloring: painting view (moved from inline <style> in 1.9.0) */
* { box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
html, body { height:100%; }
body {
    font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background:#eef2f7; color:#333; height:100vh; height:100dvh; display:flex; flex-direction:column; overflow:hidden;
    user-select:none; -webkit-user-select:none;
}
button { font-family:inherit; }
.coc-top-bar {
    flex-shrink:0; min-height:54px; background:#fff; border-bottom:1px solid #e2e8f0; display:flex; align-items:center;
    justify-content:space-between; padding:0 20px; z-index:10; gap:12px;
}
.coc-title-wrapper { display:flex; align-items:center; justify-content:space-between; gap:10px; max-width:40%; min-width:0; }
.coc-title { font-size:16px; font-weight:700; color:#1e293b; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.coc-top-actions { display:flex; align-items:center; gap:8px; }
.coc-buttons-row { display:flex; align-items:center; gap:8px; }
.coc-action-btns-group { display:flex; align-items:center; gap:6px; }
.coc-header-action-btn {
    display:inline-flex; align-items:center; gap:6px; padding:7px 13px; border-radius:9px;
    font-size:12px; font-weight:700; color:#ffffff; background:#4f46e5; border:1px solid #4338ca;
    cursor:pointer; transition:.15s; box-shadow:0 1px 3px rgba(79,70,229,.3);
}
.coc-header-action-btn:hover { background:#4338ca; border-color:#3730a3; }
.coc-header-action-btn:disabled { opacity:0.35; pointer-events:none; }
.coc-header-action-btn svg { width:15px; height:15px; flex-shrink:0; stroke-width:2.5; stroke:currentColor; }
.coc-clear-action-btn { color:#ffffff; background:#e11d48; border-color:#be123c; box-shadow:0 1px 3px rgba(225,29,72,.3); }
.coc-clear-action-btn:hover { background:#be123c; border-color:#9f1239; }
.coc-fullscreen-btn {
    display:inline-flex; align-items:center; justify-content:center;
    width:34px; height:34px; border-radius:8px; border:1px solid #cbd5e1;
    background:#38bdf8; color:#ffffff; border-color:#0ea5e9; cursor:pointer; transition:.15s;
    box-shadow:0 1px 3px rgba(14,165,233,.35); flex-shrink:0;
}
.coc-fullscreen-btn:hover { background:#0ea5e9; color:#ffffff; border-color:#0284c7; }
.coc-fullscreen-btn svg, .coc-fs-icon { width:16px; height:16px; flex-shrink:0; stroke:currentColor; }
.coc-fullscreen-btn.coc-mobile-fs-btn { display:none; }
.coc-fullscreen-active {
    position:fixed !important; top:0 !important; left:0 !important; right:0 !important; bottom:0 !important;
    width:100vw !important; height:100vh !important; height:100dvh !important; z-index:999999 !important; background:#ffffff;
}
.coc-header-btn {
    display:inline-flex; align-items:center; gap:6px; padding:7px 12px; border-radius:8px;
    font-size:12px; font-weight:700; color:#fff; border:none; cursor:pointer; transition:.15s;
    box-shadow:0 1px 2px rgba(0,0,0,.06);
}
.coc-header-btn svg { width:14px; height:14px; flex-shrink:0; }
.coc-print-btn { background:#2563eb; }
.coc-print-btn:hover { background:#1d4ed8; }
.coc-download-btn { background:#059669; }
.coc-download-btn:hover { background:#047857; }
button:focus-visible, input:focus-visible { outline:3px solid #93c5fd; outline-offset:2px; }

.coc-zoom-controls {
    display:flex; align-items:center; gap:6px; font-size:12px; color:#64748b; font-weight:600;
    background:#fcd34d; border:1px solid #f5b800; padding:4px 8px; border-radius:12px; color:#6b4a00;
    box-shadow:0 1px 3px rgba(245,184,0,.3);
}
.coc-zoom-controls button {
    background:#fff; border:1px solid #cbd5e1; height:26px; min-width:26px; border-radius:6px;
    cursor:pointer; font-weight:bold; font-size:13px; color:#334155; transition:.15s;
    padding:0 6px; display:inline-flex; align-items:center; justify-content:center; flex-shrink:0;
}
.coc-zoom-controls button:hover { background:#fff7d6; border-color:#d99a00; }
.coc-zoom-controls .coc-fit-btn { min-width:48px; font-size:11px; font-weight:700; background:#fff; }
#zoom-slider { flex:1; min-width:50px; max-width:130px; height:6px; accent-color:#3b82f6; cursor:pointer; }
#zoom-level { min-width:36px; text-align:center; font-size:11px; flex-shrink:0; }

.coc-main-container { display:flex; flex:1; min-height:0; overflow:hidden; position:relative; }
.coc-canvas-area {
    flex:1; min-width:0; min-height:0; background:#f8fafc; display:flex; position:relative; overflow:auto; padding:35px;
    scrollbar-width:thin; scrollbar-color:#cbd5e1 #f1f5f9; touch-action:none; overscroll-behavior:contain;
}
.coc-canvas-wrapper {
    margin:auto; flex-shrink:0; position:relative; background:#fff; box-shadow:0 12px 35px rgba(0,0,0,.09);
    border-radius:12px; overflow:hidden;
}
#paintCanvas { display:block; cursor:crosshair; touch-action:none; }
#scratchCanvas, #lineCanvas { position:absolute; top:0; left:0; pointer-events:none; touch-action:none; }

.coc-brush-cursor {
    position:fixed; display:none; pointer-events:none; z-index:50; border-radius:50%;
    border:1px solid #000; box-shadow:0 0 0 1px #fff, inset 0 0 0 1px #fff; transform:translate(-50%,-50%);
}

.coc-loading {
    position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); z-index:15;
    display:flex; flex-direction:column; align-items:center; gap:10px; color:#64748b; font-size:13px; font-weight:600;
}
.coc-spinner {
    width:38px; height:38px; border-radius:50%; border:4px solid #e2e8f0; border-top-color:#3b82f6;
    animation:coc-spin .8s linear infinite;
}
@keyframes coc-spin { to { transform:rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .coc-spinner { animation-duration:2s; } }

.coc-sidebar {
    width:340px; flex:none; background:#fff; border-left:1px solid #e2e8f0; display:flex; flex-direction:column;
    padding:16px 20px; overflow-y:auto; gap:16px; z-index:10;
}
.coc-section-title {
    font-size:11px; font-weight:800; text-transform:uppercase; color:#64748b; letter-spacing:.6px;
    margin-bottom:8px; display:flex; align-items:center; gap:6px;
}
.coc-tools-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:8px; }
.coc-tool-btn {
    display:flex; align-items:center; justify-content:center; gap:8px; padding:9px 10px;
    background:#f8fafc; border:1px solid #e2e8f0; border-radius:10px; cursor:pointer; font-size:12px; font-weight:600;
    color:#334155; transition:.15s;
}
.coc-tool-btn svg { width:15px; height:15px; flex-shrink:0; color:#3b82f6; }
.coc-tool-btn:hover { background:#f1f5f9; border-color:#cbd5e1; }
.coc-tool-btn.active { background:#2563eb; border-color:#2563eb; color:#ffffff; box-shadow:0 1px 3px rgba(37,99,235,0.3); }
.coc-tool-btn.active svg { color:#ffffff; }
.coc-tool-btn-wide { grid-column:span 2; }

.coc-toggle-row { display:flex; align-items:center; justify-content:space-between; font-size:12px; color:#475569; font-weight:600; padding:4px 0; }
.coc-toggle-row input { accent-color:#3b82f6; cursor:pointer; width:16px; height:16px; }
.coc-toggle-row[hidden] { display:none; }

.coc-slider-group { display:flex; flex-direction:column; gap:6px; }
.coc-slider-group label { font-size:11px; color:#64748b; font-weight:600; display:flex; justify-content:space-between; }
.coc-slider-group input[type="range"] { width:100%; accent-color:#3b82f6; cursor:pointer; }
.coc-hint { font-size:10.5px; color:#94a3b8; line-height:1.4; }

.coc-palette-guide-list { display:flex; flex-direction:column; gap:8px; }
.coc-guide-item {
    display:flex; align-items:center; gap:12px; width:100%; padding:8px 10px; background:#fff; color:inherit; font:inherit;
    border:1px solid #e2e8f0; border-radius:12px; cursor:pointer; transition:.15s; text-align:left;
}
.coc-guide-item:hover { background:#f8fafc; border-color:#cbd5e1; }
.coc-guide-item.active { background:#fff; border-color:#ec4899; box-shadow:0 0 0 2px rgba(236,72,153,.2); }
.coc-guide-swatch {
    width:36px; height:36px; border-radius:50%; border:2px solid #fff; box-shadow:0 1px 4px rgba(0,0,0,.15); flex-shrink:0; display:block;
}
.coc-guide-text { flex:1; min-width:0; display:block; }
.coc-guide-header { display:flex; align-items:center; justify-content:space-between; font-size:12px; font-weight:700; color:#1e293b; }
.coc-guide-hex { font-size:10px; font-family:monospace; color:#64748b; background:#e2e8f0; padding:1px 5px; border-radius:4px; font-weight:normal; }
.coc-guide-desc { display:block; font-size:11px; color:#64748b; margin-top:2px; line-height:1.2; }

.coc-basic-grid { display:grid; grid-template-columns:repeat(6,1fr); gap:6px; }
.coc-basic-swatch {
    display:block; width:100%; aspect-ratio:1; border-radius:15px; cursor:pointer; border:2px solid #fff; padding:0;
    box-shadow:0 1px 4px rgba(0,0,0,.15); transition:.2s; appearance:none; -webkit-appearance:none;
}
.coc-basic-swatch:hover { transform:scale(1.08); }
.coc-basic-swatch.active { transform:scale(1.12); border-color:#0f172a; box-shadow:0 2px 8px rgba(0,0,0,.25); }
.coc-custom-row { display:flex; align-items:center; gap:10px; margin-bottom:8px; font-size:12px; color:#475569; font-weight:600; }
.coc-custom-row input[type="color"] { width:44px; height:30px; padding:0; border:1px solid #cbd5e1; border-radius:8px; background:#fff; cursor:pointer; }

.coc-image-error {
    position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); width:min(90%,500px);
    padding:24px; background:#fff; border:1px solid #fecaca; border-radius:12px; color:#b91c1c;
    text-align:center; box-shadow:0 12px 35px rgba(0,0,0,.1); display:none; z-index:20;
}

/* Mobile dock: hidden on desktop, the desktop layout is unchanged. */
.coc-dock { display:none; }

@media(max-width:850px){
    /* --- Top bar: one slim row. Title | Clear | Print | Download | Fullscreen (icons only) --- */
    .coc-top-bar { flex-direction:row; flex-wrap:nowrap; align-items:center; padding:6px 10px; min-height:52px; gap:8px; }
    .coc-title-wrapper, .coc-top-actions, .coc-buttons-row, .coc-action-btns-group { display:contents; }
    .coc-title { order:1; flex:1 1 auto; min-width:0; font-size:14px; text-align:left; }
    .coc-fullscreen-btn.coc-mobile-fs-btn { display:inline-flex; order:6; width:40px; height:40px; border-radius:12px; }
    .coc-desktop-fs-btn { display:none !important; }
    .coc-zoom-controls { display:none; }
    .coc-action-btns-group .coc-header-action-btn:not(.coc-clear-action-btn) { display:none; } /* undo / redo live in the dock */
    .coc-clear-action-btn { order:3; }
    .coc-print-btn { order:4; }
    .coc-download-btn { order:5; }
    .coc-header-btn, .coc-header-action-btn { width:40px; height:40px; padding:0; justify-content:center; border-radius:12px; flex:none; }
    .coc-header-btn span, .coc-header-action-btn span { display:none; }
    .coc-header-btn svg, .coc-header-action-btn svg { width:18px; height:18px; }

    /* --- Layout: big image area, controls docked at the bottom --- */
    .coc-main-container { flex-direction:column; }
    .coc-sidebar { display:none; }
    .coc-canvas-area { padding:8px; }

    .coc-dock {
        display:flex; flex-direction:column; flex:none; gap:6px; background:#fff; border-top:1px solid #e2e8f0;
        padding:4px 0 calc(8px + env(safe-area-inset-bottom, 0px)); z-index:10;
    }

    /* Zoom strip: below the image, never on top of it */
    .coc-zoom-strip { display:flex; align-items:center; gap:8px; padding:0 12px; height:30px; font-size:11px; font-weight:600; color:#64748b; }
    .coc-zoom-strip button {
        height:26px; min-width:30px; padding:0 8px; border:1px solid #cbd5e1; border-radius:8px; background:#fff;
        color:#334155; font-size:13px; font-weight:700; cursor:pointer; flex:none;
    }
    .coc-zoom-strip .coc-fit-btn { font-size:11px; background:#f8fafc; }
    .coc-zoom-strip input[type="range"] { flex:1; min-width:40px; height:6px; accent-color:#3b82f6; cursor:pointer; }
    #zoom-level-m { min-width:34px; text-align:center; flex:none; }

    /* Palette: one single horizontally scrollable row (page colors first, then recent, then basic) */
    .coc-pal-row { display:flex; align-items:center; gap:4px; padding-right:10px; }
    .coc-pal-scroll {
        flex:1; min-width:0; display:flex; align-items:center; gap:10px; overflow-x:auto; overflow-y:hidden; padding:9px 12px 7px;
        scrollbar-width:none; -webkit-overflow-scrolling:touch; touch-action:pan-x; overscroll-behavior-x:contain;
        -webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 22px),transparent); mask-image:linear-gradient(90deg,#000 calc(100% - 22px),transparent);
    }
    .coc-pal-scroll::-webkit-scrollbar { display:none; }
    .coc-pal-scroll .coc-recent-wrap { display:contents; }
    .coc-dock-swatch {
        position:relative; flex:none; width:40px; height:40px; padding:0; border-radius:50%; border:2px solid #fff;
        box-shadow:0 0 0 1px rgba(15,23,42,.18), 0 1px 3px rgba(0,0,0,.15); cursor:pointer; appearance:none; -webkit-appearance:none;
    }
    .coc-dock-swatch.active { box-shadow:0 0 0 3px #fff, 0 0 0 5px #ec4899; }
    .coc-dock-star { position:absolute; top:-6px; right:-6px; width:17px; height:17px; pointer-events:none; filter:drop-shadow(0 0 1.5px rgba(255,255,255,.95)); }
    .coc-dock-picker {
        position:relative; flex:none; width:40px; height:40px; border-radius:50%; border:2px solid #fff; overflow:hidden; cursor:pointer;
        box-shadow:0 0 0 1px rgba(15,23,42,.18), 0 1px 3px rgba(0,0,0,.15);
        background:conic-gradient(#f28b82,#f9c74f,#b5d99c,#8ed1e6,#9aa5e0,#d7a8e0,#f28b82);
    }
    .coc-dock-picker input { position:absolute; left:-6px; top:-6px; width:calc(100% + 12px); height:calc(100% + 12px); opacity:0; cursor:pointer; border:0; padding:0; }

    /* Opacity bar */
    .coc-op-row { display:flex; align-items:center; gap:10px; padding:0 14px; font-size:11px; font-weight:700; color:#64748b; }
    .coc-op-row svg { width:16px; height:16px; flex:none; }
    .coc-op-row input[type="range"] { flex:1; min-width:0; height:24px; accent-color:#3b82f6; cursor:pointer; }
    #dock-opacity-val { min-width:36px; text-align:right; flex:none; }

    /* Context row: 4 dots (fill gap tolerance / brush size / eraser size). Space is reserved so the image never jumps. */
    .coc-ctx-row { display:flex; align-items:center; gap:8px; padding:0 10px; height:46px; }
    .coc-ctx-row.coc-ctx-off { visibility:hidden; }
    .coc-dots { flex:1; min-width:0; display:flex; gap:8px; }
    .coc-dot {
        flex:1; min-width:0; max-width:84px; height:42px; padding:0; border-radius:14px; border:1px solid #e2e8f0; background:#f8fafc;
        display:flex; align-items:center; justify-content:center; cursor:pointer;
    }
    .coc-dot i { display:block; border-radius:50%; background:#a1a1aa; }
    .coc-dot:nth-child(1) i { width:6px; height:6px; }
    .coc-dot:nth-child(2) i { width:11px; height:11px; }
    .coc-dot:nth-child(3) i { width:17px; height:17px; }
    .coc-dot:nth-child(4) i { width:24px; height:24px; }
    .coc-dot.active { background:#eff6ff; border-color:#3b82f6; }
    .coc-dot.active i { background:#2563eb; }
    .coc-protect-chip {
        flex:none; display:inline-flex; align-items:center; gap:6px; height:42px; padding:0 10px; border:1px solid #e2e8f0; border-radius:14px;
        background:#f8fafc; font-size:11px; font-weight:700; color:#475569; cursor:pointer;
    }
    .coc-protect-chip[hidden] { display:none; }
    .coc-protect-chip input { width:16px; height:16px; accent-color:#3b82f6; }

    /* Tools row: Fill | Brush | Eraser | Pan || Undo | Redo */
    .coc-tool-row { display:flex; align-items:stretch; gap:4px; padding:0 8px; }
    .coc-dock-tool, .coc-dock-act {
        flex:1; min-width:0; height:56px; padding:0; border:none; border-radius:14px; background:transparent; color:#475569;
        display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; font-size:11px; font-weight:700; cursor:pointer;
    }
    .coc-dock-tool svg, .coc-dock-act svg { width:21px; height:21px; flex:none; }
    .coc-dock-tool.active { background:#2563eb; color:#fff; box-shadow:0 2px 6px rgba(37,99,235,.35); }
    .coc-dock-tool:active, .coc-dock-act:active { transform:scale(.96); }
    .coc-dock-act:disabled { opacity:.35; pointer-events:none; }
    .coc-tool-sep { flex:none; width:1px; margin:8px 2px; background:#e2e8f0; }
}

/* Short portrait phones: tighten the dock a little so the image keeps as much room as possible */
@media(max-width:850px) and (max-height:700px) and (orientation:portrait){
    .coc-dock { gap:3px; padding-top:2px; }
    .coc-zoom-strip { height:26px; }
    .coc-dock-swatch, .coc-dock-picker { width:36px; height:36px; }
    .coc-pal-scroll { padding:8px 12px 5px; gap:9px; }
    .coc-op-row input[type="range"] { height:20px; }
    .coc-ctx-row { height:40px; }
    .coc-dot, .coc-protect-chip { height:36px; }
    .coc-dock-tool, .coc-dock-act { height:50px; }
}

/* Phones held sideways: image on the left, controls in a scrollable panel on the right */
@media(max-width:850px) and (orientation:landscape) and (max-height:540px){
    .coc-main-container { flex-direction:row; }
    .coc-dock { width:min(340px,44vw); border-top:none; border-left:1px solid #e2e8f0; overflow-y:auto; padding-top:2px; gap:2px; }
    .coc-top-bar { min-height:46px; padding:3px 10px; }
}

#coc-print-sheet { display:none; }
@media print {
    @page { margin:10mm; }
    html, body { height:auto !important; overflow:visible !important; background:#fff !important; }
    body > *:not(#coc-print-sheet) { display:none !important; }
    #coc-print-sheet {
        display:flex !important; align-items:center; justify-content:center;
        width:100%; min-height:95vh; background:#fff;
    }
    #coc-print-sheet img { max-width:100%; max-height:95vh; object-fit:contain; }
}
