    /* PROFESSIONAL COLOR PALETTE & STYLING */
    :root {
        --bg: #f5f7fc;
        --primary: #4f46e5;
        /* Primary accent is a deep blue */
        --primary-soft: #e0e7ff;
        --accent: #ff8a5c;
        /* Secondary accent is the original orange */
        --text: #1f2937;
        --text-soft: #6b7280;
        --radius-xl: 18px;
        /* Slightly tighter radius */
        --radius-lg: 12px;
        --shadow-soft: 0 4px 16px rgba(17, 24, 39, 0.06);
        --shadow-hover: 0 6px 20px rgba(17, 24, 39, 0.1);
        --transition-fast: 0.2s ease-in-out;
    }

    * {
        box-sizing: border-box;
    }

    body {
        margin: 0;
        font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
        background: radial-gradient(circle at top left, #ffffff, var(--bg));
        color: var(--text);
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    header {
        padding: 16px 30px;
        /* More padding */
        display: flex;
        align-items: center;
        gap: 16px;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(8px);
        border-bottom: 1px solid #f3f4f6;
        /* position: sticky; */
        top: 0;
        z-index: 50;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        /* Subtle header shadow */
    }

    .logo {
        width: 48px;
        /* Larger logo */
        height: 48px;
        border-radius: 999px;
        background: linear-gradient(135deg, var(--primary), var(--accent));
        box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        color: white;
    }

    header h1 {
        margin: 0;
        font-size: 20px;
        font-weight: 700;
    }

    header p {
        margin: 0;
        font-size: 13px;
        color: var(--text-soft);
    }

    .app {
        padding: 20px 30px;
        /* More padding */
        display: grid;
        grid-template-columns: 280px minmax(0, 1fr);
        /* Wider sidebar */
        gap: 20px;
        flex: 1;
    }



    /* Sidebar */
    .sidebar {
        background: #ffffff;
        border-radius: var(--radius-xl);
        padding: 18px;
        box-shadow: var(--shadow-soft);
        display: flex;
        flex-direction: column;
        gap: 16px;
        align-self: flex-start;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
        border: 1px solid #e5e7eb;
        max-width: 1000px;
    }

    .sidebar-title {
        font-size: 14px;
        font-weight: 700;
        margin-bottom: 8px;
        color: var(--primary);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    .category-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 4px;
    }

    .category-btn {
        padding: 8px 14px;
        font-size: 13px;
        border-radius: 999px;
        border: 1px solid #d1d5db;
        background: #f9fafb;
        cursor: pointer;
        transition: var(--transition-fast);
        white-space: nowrap;
        color: var(--text-soft);
        font-weight: 500;
    }

    .category-btn:hover {
        background: #f3f4f6;
        border-color: #9ca3af;
        color: var(--text);
    }

    .category-btn.active {
        background: var(--primary);
        border-color: var(--primary);
        color: #ffffff;
        font-weight: 600;
        box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
    }

    .content-section {
        margin: 40px auto;
    }

    .thumbs {
        display: flex;
        /* grid-template-columns: repeat(2, 1fr); */
        /* Two columns for larger thumbs */
        gap: 10px;
    }

    .thumb {
        position: relative;
        cursor: pointer;
        border-radius: var(--radius-lg);
        /* overflow: hidden; */
        border: 3px solid transparent;
        transition: var(--transition-fast);
        background: #f3f4f6;
        aspect-ratio: 3 / 4;
        /* display: flex; */
        align-items: center;
        justify-content: center;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
        width: 200px;
        height: 200px;
    }

    .thumb img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        filter: grayscale(100%);
        opacity: 0.8;
        transition: var(--transition-fast);
    }

    .thumb:hover {
        box-shadow: var(--shadow-hover);
        transform: translateY(-1px);
    }

    .thumb:hover img {
        opacity: 1;
    }

    .thumb.active {
        border-color: var(--accent);
        box-shadow: var(--shadow-hover);
    }

    .thumb.active img {
        filter: none;
        opacity: 1;
    }

    .hint {
        font-size: 12px;
        color: var(--text-soft);
        background: #f3f4f6;
        border-left: 4px solid var(--accent);
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        padding: 10px 12px;
    }

    /* Main area */
    .main {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 12px;
        background: #ffffff;
        border-radius: 16px;
        border: 1px solid #e5e7eb;
        box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
        align-items: center;
        width: 400px;
        margin: 10px;
    }

    .tool-group {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    /* Toolbar layout on larger screens: labels + controls in a row */
    .toolbar .tool-group {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .toolbar .tool-group .tool-label {
        margin-right: 8px;
        white-space: nowrap;
    }

    /* Let sliders have a consistent width so the bar feels aligned */
    #brushSize,
    #zoomRange {
        width: 80px;
    }

    /* Palette can wrap within its group if needed */
    #palette {
        flex-wrap: wrap;
    }

    .tool-label {
        font-size: 10px;
        text-transform: uppercase;
        color: var(--text-soft);
        letter-spacing: 0.08em;
        font-weight: 600;
    }

    #palette {
        display: flex;
        gap: 6px;
    }

    /* --- Smoothly fade in/out the Download button --- */
    #downloadBtn {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.4s ease;
        min-width: 15px;
    }

    #downloadBtn.active {
        opacity: 1;
        pointer-events: auto;
    }

    .color-swatch {
        width: 24px;
        /* Larger swatch */
        height: 24px;
        border-radius: 8px;
        border: 2px solid #ffffff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        cursor: pointer;
        transition: all var(--transition-fast);
        position: relative;
    }

    .color-swatch:hover {
        transform: scale(1.1);
    }

    .color-swatch.active {
        outline: 2px solid var(--primary);
        outline-offset: 1px;
        transform: scale(1.05);
        border-color: var(--primary-soft);
        box-shadow: 0 0 0 1px var(--primary-soft);
    }

    /* Custom color input */
    #customColor {
        width: 24px;
        height: 24px;
        padding: 0;
        margin: 0;
        opacity: 0;
        cursor: pointer;
        position: absolute;
        left: 0;
        top: 0;
    }

    .custom-swatch-wrapper {
        position: relative;
        width: 24px;
        height: 24px;
        border-radius: 8px;
        background: #f3f4f6;
        border: 1px solid #e5e7eb;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: var(--text-soft);
        transition: var(--transition-fast);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .custom-swatch-wrapper:hover {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    }

    input[type="range"] {
        accent-color: var(--primary);
    }

    /* Mode Buttons (replacing select) */
    .mode-btn {
        width: 34px;
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius-lg);
        border: 1px solid #e5e7eb;
        background: #f9fafb;
        color: var(--text-soft);
        cursor: pointer;
        transition: var(--transition-fast);
        font-size: 16px;
    }

    .mode-btn:hover {
        background: #eef2ff;
        color: var(--primary);
    }

    .mode-btn.active {
        background: var(--primary);
        border-color: var(--primary);
        color: #ffffff;
        box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
    }

    .btn {
        padding: 8px 14px;
        border-radius: 999px;
        border: 1px solid #d1d5db;
        cursor: pointer;
        font-size: 13px;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        transition: var(--transition-fast);
        background: #f9fafb;
        color: var(--text);
        font-weight: 500;
    }

    .btn:hover {
        background: #eef2ff;
        border-color: #c7d2fe;
        color: var(--primary);
    }

    .btn.primary {
        background: var(--accent);
        border-color: var(--accent);
        color: #ffffff;
        font-weight: 600;
    }

    .btn.primary:hover {
        background: #fa7b44;
        border-color: #fa7b44;
        transform: translateY(-1px);
        box-shadow: var(--shadow-soft);
    }

    .canvas-wrapper {
        position: relative;
        flex: 1;
        /*min-height: 400px;*/
        height: calc(100vh - 220px);
        max-height: 720px;
        background: #ffffff;
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-soft);
        padding: 0px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        border: 1px solid #e5e7eb;
        max-width: 1000px;
    }

    #lineCanvas,
    #drawCanvas {
        position: absolute;
        inset: 0;
        /* margin: auto; */
        max-width: 100%;
        max-height: 100%;
        border-radius: var(--radius-lg);
        box-sizing: border-box;
        touch-action: none;
        background: #ffffff;
        /* Explicit background for line layer */
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
    }

    /* Color layer needs to be above the line art for fill/brushing to work */
    #lineCanvas {
        z-index: 1;
        pointer-events: none;
    }

    #drawCanvas {
        z-index: 2;
        background: transparent;
    }



    /* === Mobile-first improvements === */

    /* Let the toolbar scroll horizontally on small screens */
    .toolbar {
        overflow-x: visible;
        -webkit-overflow-scrolling: touch;
    }



    /* Collapsible toolbar */
    .toolbar.collapsed {
        gap: 8px;
        padding: 8px 12px;
    }

    .toolbar.collapsed .tool-group:not(.persist) {
        display: none;
        /* keep only the persist group (toggle + download) visible */
    }

    /* Focus mode (hide sidebar, give canvas nearly full height) */
    .focus-mode .sidebar {
        display: none !important;
    }

    .focus-mode .app {
        grid-template-columns: 1fr !important;
    }

    .focus-mode .canvas-wrapper {
        height: calc(100vh - 140px);
        /* header + compact toolbar */
    }



    /* Fullscreen canvas tweaks */
    :fullscreen .canvas-wrapper,
    :-webkit-full-screen .canvas-wrapper {
        height: 100vh !important;
        max-height: none !important;
        border-radius: 0;
        box-shadow: none;
    }


    /* Keep the last tool-group (Download + toggles) always visible when collapsing */
    .tool-group.persist {
        /* margin-left: auto; */
        flex-shrink: 0;
    }

    /* === Landscape-first thumbnails === */
    .thumbs {
        display: flex;
        /*grid-template-columns: repeat(2, 1fr);*/
        /* desktop/tablet grid */
        gap: 10px;
        max-width: 400px;
    }

    .thumb {
        aspect-ratio: 4 / 3;
        /* landscape */
    }

    .thumb img {
        object-fit: contain;
        /* no cropping for line art */
        filter: grayscale(100%);
        opacity: 0.9;
    }



    /* --- NEW: Ad containers with reserved space (prevents layout shift) --- */
    .ad-slot {
        background: #fafafa;
        border: 1px dashed #e5e7eb;
        border-radius: 10px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, .03) inset;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #6b7280;
        font-size: 13px;
    }

    /* Top banner (desktop & mobile). Reserve height so no CLS. */
    .ad-top {
        height: 90px;
        /* desktop */
        max-height: 150px;
        margin: 12px 30px 0 30px;
        width: 100%;
        box-sizing: border-box;
        flex-shrink: 0;
        /* matches your layout padding */
    }

    #adTop ins {
        display: block;
        width: 100%;
        min-height: 50px;
    }

    /* Native unit in sidebar */
    .ad-native {
        height: 120px;
        min-height: 120px;
        margin-top: 10px;
    }

    /* Sticky footer (mobile only) */
    .ad-sticky {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 60px;
        min-height: 60px;
        z-index: 60;
        margin: 0;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
        display: none;
        /* JS toggles on mobile */
    }



    /* Interstitial overlay */
    .ad-interstitial-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 1000;
    }

    .ad-interstitial {
        width: min(90vw, 640px);
        height: min(75vh, 480px);
        background: #fff;
        border-radius: 16px;
        padding: 10px;
        box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }

    .ad-close {
        position: absolute;
        top: 8px;
        right: 10px;
        background: #111827;
        color: #fff;
        border: 0;
        border-radius: 999px;
        padding: 8px 10px;
        cursor: pointer;
        font-size: 12px;
        opacity: .85;
    }

    .ad-close[disabled] {
        opacity: .5;
        cursor: not-allowed;
    }

    .ad-caption {
        position: absolute;
        bottom: 8px;
        left: 0;
        right: 0;
        text-align: center;
        color: #6b7280;
        font-size: 12px;
    }

    /* Hide ads in focus mode for clean UX */
    .focus-mode .ad-top,
    .focus-mode .ad-sticky {
        display: none !important;
    }

    #canvasInner {
        position: relative;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        transform-origin: 0 0;
        /* changed from center center */
        min-height: 320px;
    }


    #zoomRange {
        min-width: 100px;
    }

    /* --- Enhanced Blend Color Section --- */
    #blendGroup {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        border-radius: var(--radius-lg);
        background: #f9fafb;
        box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05),
            0 1px 3px rgba(0, 0, 0, 0.08);
        border: 1px solid #e5e7eb;
        position: relative;
    }

    #blendGroup>.border-label-box:first-child {
        position: relative;
        z-index: 2;
        /* on top */
    }

    #blendPatternPanel {
        position: relative;
        z-index: 1;
        /* below the color picker palette */
    }

    #blendGroup .custom-swatch-wrapper {
        width: 50px;
        height: 40px;
        border-radius: 10px;
        border: 2px solid #ffffff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
        background: #fff;
        transition: transform 0.15s ease;
    }

    #blendGroup .custom-swatch-wrapper:hover {
        transform: scale(1.08);
    }

    #blendGroup input[type="color"] {
        width: 100%;
        height: 100%;
        border: none;
        opacity: 0;
        cursor: pointer;
    }

    #blendGroup .color-swatch {
        width: 100%;
        height: 100%;
        border-radius: inherit;
        border: 1px solid black;
    }

    #blendGroup .tool-label {
        font-size: 11px;
        font-weight: 600;
        color: var(--text-soft);
        text-transform: uppercase;
        margin-right: 8px;
    }

    /* Optional: Add small label badges below Color A/B */
    #blendGroup .custom-swatch-wrapper::after {
        content: attr(title);
        position: absolute;
        bottom: -16px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 10px;
        font-weight: 500;
        color: var(--text-soft);
    }


    #blendType {
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        padding: 6px 8px;
    }

    @media (max-width: 900px) {
        #blendType {
            font-size: 12px;
        }
    }

    /* Blend / Pattern preset panel */
    .blend-panel {
        display: grid;
        grid-auto-flow: column;
        gap: 8px;
        align-items: center;
    }

    .blend-sample {
        width: 44px;
        height: 28px;
        border-radius: 10px;
        border: 1px solid black;
        box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
        cursor: pointer;
        position: relative;
        transition: transform .05s ease-in-out;
    }

    /* ---------- Blend Color Quick Palette ---------- */
    .blend-palette {
        display: none;
        position: absolute;
        top: 110%;
        left: 0;
        padding: 6px;
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        z-index: 25;
        grid-template-columns: repeat(5, 24px);
        gap: 6px;
    }

    .blend-palette .color-dot {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        border: 1px solid #ddd;
        cursor: pointer;
        transition: transform 0.1s ease;
    }

    .blend-palette .color-dot:hover {
        transform: scale(1.1);
        border-color: #333;
    }

    /* Show palette when wrapper is active */
    .custom-swatch-wrapper.open .blend-palette {
        display: grid;
    }

    .blend-sample:active {
        transform: translateY(1px);
    }

    .blend-sample.is-active {
        outline: 2px solid red;
        /* brand purple */
        /*outline-offset: 1px;*/
        border-color: transparent;
    }

    .blend-sample:focus-visible {
        outline: 2px solid red;
        /*outline-offset: 1px;*/
    }

    /* Hide legacy swatch palette + custom picker (non-destructive) */
    .tool-group[data-role="palette"],
    .tool-group[data-role="custom"] {
        display: none !important;
    }

    .border-label-box {
        position: relative;
        border: 1px solid #ccc;
        border-radius: 10px;
        padding: 12px 5px 5px;
        /* margin-bottom: 10px; */
        background: #fff;
    }

    .border-label-box .border-label {
        position: absolute;
        top: -10px;
        left: 12px;
        background: #fff;
        padding: 0 6px;
        font-size: 12px;
        color: #555;
        font-weight: 500;
    }

    .zoom-row {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .btn-ghost {
        padding: 4px 10px;
        font-size: 12px;
        border-radius: 999px;
        border: 1px solid #e5e7eb;
        background: #ffffff;
        color: #4b5563;
    }

    .btn-ghost:hover {
        background: #f3f4f6;
    }

    .displayNone {
        display: none !important;
    }

    #resetZoomBtn {
        position: absolute;
        top: 0px;
        right: 0px;
        /* display: none; */
        z-index: 2;
        background-color: purple;
        color: white;
        display: none;
    }

    /* ===== Workspace Layout ===== */
    .workspace {

        gap: 16px;

    }