/* Quick Edit CSS - Layout & Overrides Only */

/* Reusing Generator Styles:
   - .tg-sidebar (Left panel background/blur)
   - .tg-layout (Main container)
   - .btn-primary, .btn-secondary (Buttons)
   - .tg-sidebar-textarea, .tg-num-input (Inputs)
*/

/* --- MAIN LAYOUT OVERRIDE --- */
/* We need to override .tg-layout from flex (generator) to grid (quick-edit) on desktop */
.qe-layout {
    display: grid;
    grid-template-columns: 320px 1fr 1fr;
    gap: 12px;
    padding: 12px;
    background: var(--bg-black);
    height: calc(100vh - 64px);
    overflow: hidden;
}

@media (max-width: 1200px) {
    .qe-layout {
        grid-template-columns: 280px 1fr 1fr;
        gap: 8px;
        padding: 8px;
    }
}

/* Sidebar/center/right shared by editor-foundation.css */

/* STABILITY GUARDRAIL:
   #qe-size-slider-desktop is shared by Sketch + Magic Blend desktop.
   Keep thumb contained inside track and high-contrast (current approved look). */
/* Sketch + Magic Blend desktop brush slider:
   match the glossy mobile slider language */
#qe-size-slider-desktop.tg-sidebar-slider {
    -webkit-appearance: none;
    appearance: none;
    height: 14px;
    border-radius: 999px;
    background:
        linear-gradient(180deg, rgba(34, 197, 94, 0.16) 0%, rgba(2, 6, 23, 0.06) 100%),
        linear-gradient(90deg, rgba(16, 185, 129, 0.9) 0%, rgba(16, 185, 129, 0.78) 52%, rgba(13, 45, 38, 0.72) 100%);
    border: 1px solid rgba(16, 185, 129, 0.36);
    box-shadow:
        inset 0 1px 1px rgba(34, 197, 94, 0.2),
        inset 0 -1px 2px rgba(2, 6, 23, 0.58),
        0 4px 12px rgba(2, 6, 23, 0.34);
}

#qe-size-slider-desktop.tg-sidebar-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(15, 23, 42, 0.9);
    background:
        radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 1) 0%, rgba(248, 250, 252, 0.98) 45%, rgba(226, 232, 240, 0.95) 75%, rgba(203, 213, 225, 0.92) 100%);
    box-shadow:
        0 4px 10px rgba(2, 6, 23, 0.35),
        0 0 0 1px rgba(15, 23, 42, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 1),
        inset -3px -4px 6px rgba(148, 163, 184, 0.35);
    cursor: pointer;
}

#qe-size-slider-desktop.tg-sidebar-slider::-moz-range-track {
    height: 14px;
    border-radius: 999px;
    border: 1px solid rgba(16, 185, 129, 0.36);
    background:
        linear-gradient(180deg, rgba(34, 197, 94, 0.16) 0%, rgba(2, 6, 23, 0.06) 100%),
        linear-gradient(90deg, rgba(16, 185, 129, 0.9) 0%, rgba(16, 185, 129, 0.78) 52%, rgba(13, 45, 38, 0.72) 100%);
    box-shadow:
        inset 0 1px 1px rgba(34, 197, 94, 0.2),
        inset 0 -1px 2px rgba(2, 6, 23, 0.58),
        0 4px 12px rgba(2, 6, 23, 0.34);
}

#qe-size-slider-desktop.tg-sidebar-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(15, 23, 42, 0.9);
    background:
        radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 1) 0%, rgba(248, 250, 252, 0.98) 45%, rgba(226, 232, 240, 0.95) 75%, rgba(203, 213, 225, 0.92) 100%);
    box-shadow:
        0 4px 10px rgba(2, 6, 23, 0.35),
        0 0 0 1px rgba(15, 23, 42, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 1),
        inset -3px -4px 6px rgba(148, 163, 184, 0.35);
    cursor: pointer;
}

.qe-layer-fab {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 30;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(16, 185, 129, 0.22);
    background: rgba(2, 12, 20, 0.82);
    color: var(--neon-green);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(0,0,0,0.35);
    cursor: pointer;
}

.qe-layer-popover {
    position: absolute;
    top: 66px;
    right: 14px;
    z-index: 29;
    width: 320px;
    max-width: min(320px, calc(100% - 28px));
    max-height: calc(100% - 80px);
    overflow: hidden;
    border-radius: 16px;
    border: 1px solid rgba(16, 185, 129, 0.16);
    background: rgba(2, 6, 23, 0.94);
    backdrop-filter: blur(14px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.qe-layers-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.qe-layers-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.qe-layer-icon-btn {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.04);
    color: var(--neon-green);
    cursor: pointer;
}

.qe-layer-count {
    color: var(--text-dim);
    font-size: 0.82rem;
}

.qe-layers-panel-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    gap: 12px;
}

.qe-layers-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.qe-layer-mini-btn {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.78rem;
}

.qe-layers-list {
    flex: 1;
    min-height: 180px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

.qe-layer-empty {
    color: var(--text-dim);
    font-size: 0.85rem;
    text-align: center;
    padding: 20px 12px;
    border: 1px dashed var(--glass-border);
    border-radius: 12px;
}

.qe-layer-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 28px;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.03);
    cursor: pointer;
}

.qe-layer-row.active {
    border-color: var(--neon-green);
    box-shadow: 0 0 0 1px rgba(16,185,129,0.25), 0 0 18px rgba(16,185,129,0.12);
    background: rgba(16,185,129,0.08);
}

.qe-layer-thumb {
    width: 34px;
    height: 46px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
    background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
    display: flex;
    align-items: center;
    justify-content: center;
}

.qe-layer-thumb canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.qe-layer-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.qe-layer-name {
    color: var(--text-white);
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qe-layer-sub {
    color: var(--text-dim);
    font-size: 0.75rem;
}

.qe-layer-eye {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    background: rgba(255,255,255,0.03);
    border: 1px solid transparent;
}

.qe-layer-eye.is-visible {
    color: var(--neon-green);
}

.qe-layer-controls {
    border-top: 1px solid var(--glass-border);
    padding-top: 12px;
}

.qe-layer-control-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    color: var(--text-dim);
    font-size: 0.82rem;
}

/* --- COMPONENTS --- */

/* OPTIMIZATION: Remove 300ms tap delay on touch devices */
button,
.btn,
.qe-tool-btn,
.qe-action-btn,
.qe-m-tool,
.qe-m-text-btn,
#btn-m-undo,
#btn-m-redo,
#btn-ts-undo,
#btn-ts-redo {
    touch-action: manipulation;
}

/* Tools Row */
.qe-tools-row {
    display: flex;
}

.qe-tool-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* shared spacing/size in editor-shell.css */
}

.qe-tool-btn span {
    font-size: 0.7rem;
    font-weight: 500;
}

/* Active State Hook for btn-secondary */
.qe-tool-btn.active {
    background: var(--surface-hover);
    border-color: var(--neon-green) !important;
    color: var(--text-white);
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.2);
}

/* Actions Grid */
.qe-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.mt-2 {
    margin-top: 8px;
}

.qe-action-btn {
    /* shared spacing/size in editor-shell.css */
}

.tg-num-input {
    color: var(--neon-green) !important;
}

/* --- Style Dropdown Unification Refinements --- */
.tg-style-container-side {
    margin-bottom: 12px;
    width: 100%;
}

.tg-style-container-mobile {
    flex: 1.2; /* Give style dropdown more priority in mobile row */
    min-width: 0;
}

/* Ensure Sketch sidebar doesn't clip the dropdown menu */
.qe-sidebar {
    /* overflow-y visible was reverted to restore scrollability */
}

/* Mobile Composer adjustments */
.tg-params-row .tg-param-group {
    min-width: 0;
}

/* Match Generator's trigger style if not already covered */
.tg-mini-select-trigger, .tg-select-trigger {
    cursor: pointer;
}


/* Canvas Wrap */
.qe-canvas-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qe-canvas-wrap canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    /* Slight radius */
}

#canvas-mask {
    z-index: 10;
    opacity: 0.6;
}

#canvas-base {
    z-index: 5;
}

/* Output */
.qe-output-wrap {
    width: 100%;
    flex: 1 1 auto;
    /* Fill remaining height */
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    margin-bottom: 0;
    /* Removed previous margin */
    position: relative;
    overflow: hidden;
}

.qe-media-img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.qe-placeholder {
    color: var(--text-dim);
    text-align: center;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.qe-download-btn {
    position: absolute;
    bottom: 20px;
    width: calc(100% - 40px);
}

/* Mobile Toggles */
.qe-mobile-sliders,
.qe-mobile-upload-btn,
.tg-composer {
    display: none !important;
    /* Hidden on desktop */
}

@media (min-width: 901px),
(orientation: landscape) and (min-width: 769px) {
    /* Sketch desktop: lock body scroll — app-like stable viewport */
    html body.tg-body:not(.stencil-page) {
        height: 100vh !important;
        overflow: hidden !important;
    }

    #qe-upload-desktop-btn {
        display: inline-flex !important;
    }

    /* Keep steps input compact */
    #qe-steps {
        width: 64px !important;
        flex: 0 0 64px !important;
        max-width: 64px !important;
        box-sizing: border-box !important;
    }

    /* Prevent res-box wrapper from stretching too wide */
    .qe-sidebar .res-box {
        flex: 0 0 auto !important;
        width: 80px !important;
        min-width: 80px !important;
        max-width: 80px !important;
    }

    /* Desktop-only panel fit tightening */
    .qe-sidebar {
        padding: 8px 14px !important;
        overflow-y: auto !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }

    .qe-sidebar::-webkit-scrollbar {
        display: none;
    }

    .qe-sidebar .sidebar-section {
        margin-bottom: 5px !important;
    }

    .qe-sidebar .sidebar-section label {
        margin-bottom: 3px !important;
        font-size: 0.7rem !important;
    }

    #qe-prompt-desktop.tg-sidebar-textarea {
        min-height: 96px !important;
        height: 96px !important;
        padding: 8px !important;
        font-size: 16px !important;
        color: var(--text-white) !important;
    }

    .pa-trigger-btn--sidebar {
        min-height: 32px !important;
        padding: 6px 10px !important;
    }

    .qe-tool-btn {
        height: 52px !important;
        padding: 4px !important;
    }

    .qe-action-btn {
        height: 34px !important;
    }

    .tg-sidebar-slider {
        margin-top: 6px !important;
    }

    .sidebar-footer {
        margin-top: 6px !important;
    }

    .tg-sidebar-generate-btn {
        padding: 9px !important;
        font-size: 0.82rem !important;
    }

    #qe-steps {
        height: 34px !important;
    }

    #qe-upload-desktop-btn {
        height: 34px !important;
        padding: 0 10px !important;
    }

    #qe-credits {
        margin-top: 6px !important;
        font-size: 0.75rem !important;
    }
}

@media (max-width: 600px) {
    #qe-mobile-composer #qe-prompt-mobile.tg-prompt-textarea {
        overflow-y: hidden !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    #qe-mobile-composer #qe-prompt-mobile.tg-prompt-textarea::-webkit-scrollbar {
        display: none;
        width: 0;
    }
}

/* --- MOBILE LAYOUT (<= 768px) AND TABLET PORTRAIT (<= 1024px) --- */
@media (max-width: 600px),
(min-width: 601px) and (max-width: 1024px) {

    /* STRICT LOCK: Prevent full-screen scrolling behavior on iPad/Mobile */
    html,
    body {
        width: 100%;
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
        touch-action: none;
    }

    .desktop-only {
        display: none !important;
    }

    .qe-layer-fab {
        display: inline-flex !important;
        position: fixed;
        top: 72px;
        right: 12px;
        z-index: 13010;
    }

    #qe-canvas-container {
        isolation: auto;
    }

    .qe-layer-popover {
        position: fixed;
        top: 124px;
        right: 12px;
        left: auto;
        width: min(320px, calc(100vw - 24px));
        max-width: min(320px, calc(100vw - 24px));
        max-height: calc(100vh - 140px);
        z-index: 13000;
        pointer-events: auto;
    }

    .mobile-only {
        display: flex !important;
    }

    @media (max-width: 767px) {
        .qe-layer-fab {
            top: 68px;
            right: 10px;
            width: 38px;
            height: 38px;
            border-radius: 10px;
            z-index: 20010 !important;
        }

        .qe-layer-popover {
            position: fixed !important;
            top: 112px !important;
            right: 10px !important;
            left: auto !important;
            bottom: 8px !important;
            width: min(200px, calc(100vw - 20px)) !important;
            max-width: min(200px, calc(100vw - 20px)) !important;
            height: auto !important;
            max-height: calc(100vh - 120px) !important;
            min-height: auto !important;
            padding: 6px;
            gap: 4px;
            border-radius: 12px;
            overflow: hidden;
            overscroll-behavior: contain;
            z-index: 20000 !important;
        }

        .qe-layer-popover .qe-layer-thumb {
            width: 38px;
            height: 52px;
        }

        .qe-layer-popover .qe-layer-thumb canvas {
            width: 38px !important;
            height: 52px !important;
        }

        .qe-layer-popover .qe-layers-panel-body {
            min-height: 0;
            overflow: hidden;
        }

        .qe-layer-popover .qe-layers-list {
            flex: 1 1 auto;
            min-height: 160px;
            max-height: none;
            overflow-y: auto;
            overflow-x: hidden;
            border-left: 0 !important;
            box-shadow: none !important;
            scrollbar-width: none;
            padding-right: 0;
            -webkit-overflow-scrolling: touch;
            touch-action: pan-y;
        }

        .qe-layer-popover .qe-layers-list::-webkit-scrollbar {
            display: none;
        }

        .qe-layer-popover .qe-layer-controls {
            flex: 0 0 auto;
            padding-top: 6px;
            margin-top: 2px;
            position: relative;
            z-index: 2;
            background: rgba(2, 6, 23, 0.96);
        }

        .qe-layer-popover #qe-layer-opacity {
            display: block !important;
            visibility: visible !important;
            opacity: 1 !important;
            width: 100%;
            min-width: 0;
            margin: 0;
        }

        .qe-layer-popover .qe-layer-row {
            padding: 6px;
            gap: 6px;
            grid-template-columns: 38px minmax(0, 1fr) 24px;
        }

        .qe-layer-popover .qe-layer-eye {
            width: 24px;
            height: 24px;
            flex: 0 0 24px;
        }

        .qe-layer-popover .qe-layer-eye svg {
            width: 13px;
            height: 13px;
        }

        .qe-layer-popover .qe-layer-name {
            font-size: 0.78rem;
        }

        .qe-layer-popover .qe-layer-sub,
        .qe-layer-popover .qe-layer-count,
        .qe-layer-popover .qe-layer-control-head {
            font-size: 0.66rem;
        }

        .qe-layer-popover .qe-layer-mini-btn {
            min-height: 28px;
            padding: 4px 6px;
            font-size: 0.68rem;
        }
    }

    /* Force placeholder behavior: Keep space but hide content */
    #btn-download-mobile {
        display: inline-flex !important;
        visibility: hidden !important;
    }

    /* Show only when class is added via JS */
    #btn-download-mobile.show-download {
        visibility: visible !important;
    }

    #qe-mobile-upload-btn {
        display: inline-flex !important;
        width: 48px;
        height: 48px;
        flex: 0 0 48px;
    }

    /* LAYOUT: Hide Desktop Panels Visually */
    .qe-sidebar,
    .qe-panel-right {
        display: none !important;
    }

    /* Reset Main Grid to Block */
    .qe-layout {
        display: block;
        height: 100%;
        /* Force strict height base */
        min-height: 100vh;
        /* Fallback */
        position: relative;
    }

    /* Center Panel (Canvas) */
    .qe-panel-center {
        position: fixed;
        top: 64px;
        left: 60px;
        /* Space for Tool Strip */
        right: 0;
        bottom: 80px;
        /* Space for Prompt Bar */
        width: auto;
        height: auto;
        padding: 0;
        background: #000;
        z-index: 10;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #qe-canvas-container {
        width: 100%;
        height: 100%;
    }

    /* Mobile Tool Strip (Left) */
    #qe-mobile-tool-strip {
        position: fixed;
        top: 64px;
        left: 0;
        bottom: 0;
        /* Removed bottom: 60px — was leaving black gap below buttons */
        width: 60px;
        background: rgba(6, 23, 16, 0.65);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-right: 1px solid rgba(16, 185, 129, 0.15);
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        padding: 4px 0;
        /* Tighter padding to fit all tools */
        z-index: 50;
        overflow-y: auto;
        /* Allow scroll if strip overflows on small screens */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    #qe-mobile-tool-strip::-webkit-scrollbar {
        display: none;
    }

    .qe-layer-fab:hover,
    .qe-layer-fab:active {
        transform: translateY(-1px);
    }

    .qe-m-tool {
        width: 40px;
        /* Slightly smaller */
        height: 40px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--glass-border);
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-dim);
        transition: all 0.2s;
        flex-shrink: 0;
    }

    /* Gray/Neutral Undo/Redo (Responsive) */
    #btn-m-undo,
    #btn-m-redo,
    #btn-ts-undo,
    #btn-ts-redo {
        color: var(--text-dim);
        border-color: var(--glass-border);
        pointer-events: auto;
        z-index: 60;
    }

    #btn-m-undo:active,
    #btn-m-redo:active,
    #btn-ts-undo:active,
    #btn-ts-redo:active {
        background: rgba(255, 255, 255, 0.1);
        color: white;
    }

    #btn-m-undo:disabled,
    #btn-m-redo:disabled,
    #btn-ts-undo:disabled,
    #btn-ts-redo:disabled {
        opacity: 0.3;
        pointer-events: auto !important;
        /* Always allow taps */
        cursor: default;
    }

    .qe-phone-spinner {
        width: 22px;
        height: 22px;
        border: 2.5px solid rgba(16, 185, 129, 0.18);
        border-top-color: var(--neon-green);
        border-radius: 50%;
        animation: qe-phone-spin 0.9s linear infinite;
        flex: 0 0 auto;
        margin-left: 8px;
        align-self: center;
    }

    @keyframes qe-phone-spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }

    /* Text Buttons (Clear, Upload) */
    .qe-m-text-btn {
        flex-direction: column;
        gap: 2px;
        font-size: 8px;
        text-transform: uppercase;
        font-weight: 700;
        line-height: 1;
        color: var(--neon-green);
        border-color: rgba(16, 185, 129, 0.3);
        height: auto;
        padding: 4px 2px;
        min-height: 40px;
    }

/* Force history button state */
    .history-active {
        opacity: 1 !important;
        pointer-events: auto !important;
        cursor: pointer !important;
        filter: none !important;
    }

    .qe-m-slider-container {
        height: 60px;
        width: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 10px;
        margin-bottom: 10px;
    }

    /* Mobile Steps Input (Tiny) */
    .qe-steps-mini {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        margin-bottom: 4px;
        /* Space before Undo */
    }

    .qe-steps-label {
        font-size: 8px;
        color: var(--text-dim);
        margin-bottom: 2px;
        text-transform: uppercase;
        font-weight: 700;
        letter-spacing: 0.5px;
    }

    #qe-steps-input {
        width: 36px;
        height: 24px;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid var(--glass-border);
        border-radius: 4px;
        color: white;
        text-align: center;
        font-size: 16px;
        /* CRITICAL: Must be 16px to prevent iOS zoom/floating keyboard */
        padding: 0;
        appearance: none;
        -moz-appearance: textfield;
        scroll-margin: 0;
        scroll-padding: 0;
    }

    #qe-steps-input:focus {
        border-color: var(--neon-green);
        background: rgba(255, 255, 255, 0.1);
        outline: none;
    }

    #qe-steps-input::-webkit-inner-spin-button,
    #qe-steps-input::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }

    .qe-m-slider {
        width: 60px;
        height: 20px;
        transform: rotate(-90deg);
        transform-origin: center;
        -webkit-appearance: none;
        appearance: none;
    }

    /* Prompt Bar (Mobile Composer) - Matches Generator Style */
    #qe-mobile-composer.tg-composer {
        display: block !important;
        position: fixed;
        bottom: 0px;
        left: 60px;
        right: 0;
        width: auto;
        min-height: 0;
        padding: 8px;
        z-index: 9999;
        border-radius: 0;
        max-width: none;
        overflow: visible !important;
        transform: translateY(calc(-1 * var(--kb-offset, 0px))) !important;
        transition: transform 0.2s ease-out;
    }

    #qe-mobile-composer .tg-input-row {
        display: flex;
        gap: 10px;
        align-items: center;
        padding: 0;
    }

    #qe-mobile-composer .tg-prompt-wrapper {
        flex: 1;
        background: rgba(255, 255, 255, 0.04);
        backdrop-filter: blur(0px);
        border: 1px solid rgba(255, 255, 255, 0.10);
        border-radius: 12px;
        display: flex;
        align-items: center;
        transition: all 0.2s ease;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 24px rgba(0, 0, 0, 0.16);
    }

    #qe-mobile-composer .tg-num-input,
    #qe-mobile-composer textarea,
    #qe-mobile-composer select,
    #qe-mobile-composer input {
        scroll-margin: 0;
        scroll-padding: 0;
    }

    #qe-mobile-composer .tg-prompt-wrapper:focus-within {
        border-color: var(--neon-green);
        background: rgba(255, 255, 255, 0.08);
    }

    #qe-mobile-composer .tg-prompt-textarea {
        width: 100%;
        min-height: 48px;
        max-height: 120px;
        padding: 12px;
        background: transparent;
        border: none;
        color: var(--text-white);
        font-family: inherit;
        font-size: 16px;
        /* CRITICAL: Must be 16px to prevent iOS zoom/floating keyboard */
        outline: none;
        resize: none;
        overflow-y: auto;
    }

    #qe-mobile-composer .tg-prompt-textarea::placeholder {
        color: #94a3b8;
    }

}

/* Tablet Landscape: Prevent Scroll on Canvas Interaction Only */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {

    #qe-canvas-container,
    .qe-canvas-wrap,
    #canvas-mask,
    #canvas-base {
        touch-action: none !important;
        overscroll-behavior: contain;
    }
}

/* Shared header text wrapping baseline */
.nav-container .brand+span {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    line-height: 1.2;
}

/* Tablet portrait ghost image and misalignment (address bar resize) */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {

    /* Mobile Back Button (Portrait Only) */
    .btn-mobile-back {
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: var(--text-white);
        padding: 4px;
        cursor: pointer;
        z-index: 100;
        transition: opacity 0.2s;
    }

    .btn-mobile-back svg {
        width: 20px;
        height: 20px;
    }

    /* 1. Force container constraints and stability */
    .qe-canvas-wrap {
        position: relative !important;
        overflow: hidden !important;
        /* Ensure it hasn't collapsed */
        height: 100%;
        width: 100%;
    }

    /* 2. Keep canvas stable but let JS own viewport transform/position */
    .qe-canvas-wrap canvas {
        position: absolute !important;
        /* Do NOT pin top/left/transform here; viewport controller sets them. */
        max-width: none !important;
        max-height: none !important;
    }

    /* 3. Hide any unintended image layers */
    .qe-canvas-wrap img {
        display: none !important;
        visibility: hidden !important;
    }

}

/* Desktop widescreen: hide back button */
@media (min-width: 1025px) {

    #qe-mobile-back,
    #sketch-mobile-back,
    .btn-mobile-back {
        display: none !important;
    }
}

/* --- LAYERS PANEL --- */
.qe-layers-panel {
    align-items: stretch;
    justify-content: flex-start;
    gap: 14px;
    background: rgba(2, 6, 23, 0.35);
}

#qe-layer-popover {
    pointer-events: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

#qe-layer-popover * {
    pointer-events: auto;
}

#qe-layer-popover button,
#qe-layer-popover input,
#qe-layer-popover .qe-layer-row,
#qe-layer-popover .qe-layer-eye,
#qe-layer-popover .qe-layer-mini-btn {
    touch-action: manipulation;
}

#qe-layer-popover input[type="range"] {
    touch-action: pan-x;
}

#qe-layer-popover .qe-layer-thumb {
    width: 36px;
    height: 48px;
    flex: 0 0 36px;
}

#qe-layer-popover .qe-layer-thumb canvas {
    position: static !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    transform-origin: center center !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    display: block !important;
    object-fit: contain;
    image-rendering: auto;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    will-change: auto !important;
}

#qe-layer-popover .qe-layer-row {
    grid-template-columns: 36px minmax(0, 1fr) 24px;
}

#qe-layer-popover .qe-layers-actions-quad {
    grid-template-columns: repeat(2, 1fr);
}

/* --- SKETCH RECENTS STRIP --- */
.sketch-recents-strip {
    display: flex;
    flex-direction: row;
    flex: 1;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 0 12px;
    height: 100%;
    overflow: hidden;
    /* Hide anything beyond limit */
}

.sketch-recent-thumb {
    width: 40px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sketch-recent-thumb:hover {
    border-color: var(--neon-green);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

/* Limit visible items - hide anything past 10 on desktop */
.sketch-recent-thumb:nth-child(n+11) {
    display: none !important;
}

@media (max-width: 600px) {
    .sketch-recents-strip {
        padding-left: 48px;
        /* Offset to clear the back button on mobile portrait */
        justify-content: flex-start;
        /* Flow from left to right after clearing button */
    }
}

@media (min-width: 601px) and (max-width: 1024px) {
    /* iPad/Tablet: two fixed clusters, top tools + bottom actions */
    #qe-mobile-tool-strip {
        position: fixed !important;
        top: 64px !important;
        left: 0 !important;
        bottom: 60px !important;
        width: 60px !important;
        display: block !important;
        padding: 0 !important;
        z-index: 50 !important;
        overflow: hidden !important;
    }

    .qe-m-tool {
        width: 40px !important;
        height: 40px !important;
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.2s !important;
        flex-shrink: 0 !important;
        position: absolute !important;
        left: 10px !important;
    }

    #btn-m-undo,
    #btn-m-redo,
    #btn-ts-undo,
    #btn-ts-redo {
        color: var(--text-dim) !important;
        border-color: var(--glass-border) !important;
        pointer-events: auto !important;
        z-index: 60 !important;
    }

    #btn-m-undo:active,
    #btn-m-redo:active,
    #btn-ts-undo:active,
    #btn-ts-redo:active {
        background: rgba(255, 255, 255, 0.1) !important;
        color: white !important;
    }

    #btn-m-undo:disabled,
    #btn-m-redo:disabled,
    #btn-ts-undo:disabled,
    #btn-ts-redo:disabled {
        opacity: 0.3 !important;
        pointer-events: auto !important;
        cursor: default !important;
    }

    #qe-mobile-upload-btn {
        display: flex !important;
        position: absolute !important;
        left: 6px !important;
        bottom: 2px !important;
        width: 48px !important;
        height: 48px !important;
        flex: 0 0 48px !important;
        margin: 0 !important;
        background: rgba(16, 185, 129, 0.1) !important;
        cursor: pointer !important;
    }

    .qe-m-upload-icon-small {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin-bottom: 2px !important;
    }

    .qe-m-slider-container {
        position: absolute !important;
        left: 10px !important;
        top: 74px !important;
        margin: 0 !important;
    }

    .qe-steps-mini {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        position: absolute !important;
        left: 10px !important;
        bottom: 236px !important;
        margin: 0 !important;
    }

    .qe-steps-label {
        font-size: 8px !important;
        color: var(--text-dim) !important;
        margin-bottom: 2px !important;
        text-transform: uppercase !important;
        font-weight: 700 !important;
        letter-spacing: 0.5px !important;
    }

    /* Top cluster positions */
    #btn-ts-marker {
        top: 12px !important;
    }

    #btn-ts-eraser {
        top: 146px !important;
    }

    #btn-ts-select {
        top: 198px !important;
    }

    /* Bottom cluster positions */
    #btn-ts-undo {
        bottom: 172px !important;
    }

    #btn-ts-redo {
        bottom: 120px !important;
    }

    #btn-ts-clear {
        bottom: 60px !important;
        left: 6px !important;
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        min-height: 48px !important;
        padding: 4px 2px !important;
    }

}

/* Tablet (iPad / coarse pointer) only: recents strip flows left → right, new items added to the right side. */
@media (min-width: 768px) and (max-width: 1024px) {
    .sketch-recents-strip {
        flex-direction: row;
        justify-content: flex-start !important;
        padding: 0 12px !important;
    }
}

/* iPad/tablet portrait only (Sketch page): keep recents starting point aligned with Magic Blend behavior. */
@media (min-width: 601px) and (max-width: 1024px) and (orientation: portrait) {
    html body:not(.magic-blend-page) .sketch-recents-strip {
        flex-direction: row !important;
        justify-content: flex-start !important;
        padding: 0 12px !important;
    }
}

/* Mobile (below 600px) only: pad to clear back button, left-to-right flow. */
@media (max-width: 600px) {
    .sketch-recents-strip {
        padding-left: 48px;
        justify-content: flex-start;
    }
}

/* Phone only: remove glass bleed behind left tool strip. */
@media (max-width: 600px) and (orientation: portrait) {
    #qe-mobile-tool-strip {
        background: rgba(6, 23, 16, 0.92) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-right: 1px solid rgba(16, 185, 129, 0.08) !important;
        box-shadow: none !important;
    }

    #qe-mobile-tool-strip #btn-ts-marker,
    #qe-mobile-tool-strip #btn-ts-eraser,
    #qe-mobile-tool-strip #btn-ts-select,
    #qe-mobile-tool-strip #btn-m-marker,
    #qe-mobile-tool-strip #btn-m-eraser,
    #qe-mobile-tool-strip #btn-ts-marker.active,
    #qe-mobile-tool-strip #btn-ts-eraser.active,
    #qe-mobile-tool-strip #btn-ts-select.active,
    #qe-mobile-tool-strip #btn-m-marker.active,
    #qe-mobile-tool-strip #btn-m-eraser.active {
        background: rgba(7, 20, 34, 0.94) !important;
        box-shadow: none !important;
    }
}

/* Phone only: limit to 5 thumbnails */
@media (max-width: 767px) {
    .sketch-recent-thumb:nth-child(n+6) {
        display: none !important;
    }
}

/* Sketch-only tweak on top of shared phone portrait header rules. */
@media (max-width: 767px) and (orientation: portrait) {
    /* Keep Sketch strip layout stable after shared offsets are applied. */
    .nav-container > div:first-child {
        position: static !important;
    }
}

/* Android phone portrait: fit 5 thumbnails using full available header width */
@media (max-width: 480px) and (orientation: portrait) {

    /* Reduce container padding so strip has more room */
    .nav-container.container {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    .sketch-recents-strip {
        padding-left: 32px;
        padding-right: 4px;
        gap: 5px;
        justify-content: flex-start;
        min-width: 0;
    }

    .sketch-recent-thumb {
        width: 36px;
        height: 42px;
        border-radius: 3px;
    }

    /* Shrink nav-actions gap on phone */
    .nav-actions {
        gap: 4px !important;
    }
}

/* Phone only: force Sketch header recents to match Quick Edit geometry exactly */
@media (max-width: 600px) and (orientation: portrait) {
    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) .main-header .nav-container {
        position: relative !important;
        display: flex !important;
        align-items: center !important;
    }

    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) .app-brand-wrap,
    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) .nav-actions.app-nav-actions-shrink {
        position: relative !important;
        z-index: 2 !important;
        flex: 0 0 auto !important;
    }

    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) #sketch-recents-strip {
        position: absolute !important;
        left: 116px !important;
        right: 58px !important;
        top: 50% !important;
        display: flex !important;
        width: auto !important;
        flex: 0 1 auto !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 48px !important;
        padding: 0 !important;
        gap: 5px !important;
        justify-content: flex-start !important;
        align-items: center !important;
        overflow: hidden !important;
        transform: translateY(-50%) !important;
        box-sizing: border-box !important;
        z-index: 1 !important;
    }

    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) #sketch-recents-strip .sketch-recent-thumb {
        width: 34px !important;
        height: 42px !important;
        object-fit: cover !important;
        object-position: center !important;
        border-radius: 4px !important;
        flex: 0 0 34px !important;
    }

    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) #sketch-recents-strip .sketch-recent-thumb:nth-child(n+6) {
        display: none !important;
    }

    body.tg-body:not(.magic-blend-page):not(.quick-edit-page):not(.stencil-page) .nav-actions.app-nav-actions-shrink {
        width: 56px !important;
        min-width: 56px !important;
        justify-content: flex-end !important;
        margin-left: auto !important;
    }
}

/* iPad portrait: modal buttons safe spacing for browser address bar */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .sketch-preview-modal {
        padding: 10px;
        padding-bottom: 0;
        box-sizing: border-box;
    }

    .sketch-preview-content {
        padding-top: 20px;
        max-height: calc(100vh - 30px);
    }

    .sketch-preview-img-wrap {
        flex: 1 1 auto;
        min-height: 0;
        max-height: calc(100vh - 200px);
        /* Allow room for buttons + browser UI */
        margin-bottom: 8px;
    }

    .sketch-preview-actions {
        padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
        flex-shrink: 0;
    }
}

/* --- SKETCH PREVIEW MODAL --- */
.sketch-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sketch-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(2, 6, 23, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.sketch-preview-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
    max-width: 800px;
    /* Constrain width of preview content */
    height: 100%;
    max-height: 90vh;
    /* Don't exceed screen height */
    z-index: 1;
}

.sketch-preview-close {
    position: absolute;
    top: -10px;
    right: 0;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 2;
}

.sketch-preview-close:hover {
    background: var(--surface-hover);
    color: var(--neon-green);
}

.sketch-preview-img-wrap {
    flex: 1;
    width: 100%;
    min-height: 0;
    /* Important for flex child image to shrink */
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    padding: 10px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 0, 0, 0.5);
}

#sketch-preview-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.sketch-preview-actions {
    display: flex;
    flex-wrap: wrap;
    /* allow wrapping on very small screens */
    gap: 12px;
    justify-content: center;
    width: 100%;
    flex-shrink: 0;
    /* Don't squash buttons */
}

.sp-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.05);
    /* Match global btn-secondary */
    min-width: 120px;
}

/* Ensure layout is stackable for mobile */
@media (max-width: 767px) {
    #qe-style-container-mobile {
        width: auto !important;
        flex: 0 0 auto !important;
    }

    #qe-style-container-mobile .tg-custom-select {
        width: auto !important;
        display: inline-block !important;
    }

    #qe-style-container-mobile .tg-mini-select-trigger {
        width: auto !important;
        max-width: 118px !important;
        min-width: 0 !important;
        padding-right: 8px !important;
        overflow: hidden !important;
    }

    #qe-style-container-mobile .tg-mini-select-trigger span {
        display: block !important;
        max-width: 78px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
}

@media (max-width: 1024px) {
    .sketch-preview-modal {
        padding: 10px;
        padding-bottom: 0;
        box-sizing: border-box;
    }

    .sketch-preview-content {
        justify-content: flex-start;
        padding-top: 30px;
        height: 100%;
        max-height: calc(100vh - 40px);
        /* Safe area */
    }

    .sketch-preview-img-wrap {
        flex: 1 1 auto;
        min-height: 0;
        /* Critical for shrinking */
        max-height: calc(100vh - 240px);
        /* Reduced to guarantee button visibility on Android */
        margin-bottom: 8px;
    }

    #sketch-preview-img {
        max-height: 100%;
        width: auto;
    }

    .sketch-preview-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
        /* Android browser bottom UI / nav bar safe spacing */
        flex-shrink: 0;
        width: 100%;
    }

    .sp-btn {
        padding: 10px 5px;
        font-size: 12px;
        min-width: 0;
        width: 100%;
    }
}
@media (max-width: 600px) {
    .sketch-preview-modal {
        height: 100dvh;
        align-items: flex-start;
        padding: 8px 8px calc(84px + env(safe-area-inset-bottom, 0px));
        overflow: hidden;
    }

    .sketch-preview-content {
        gap: 10px;
        padding-top: 22px;
        height: 100%;
        max-height: calc(100dvh - 16px);
        justify-content: flex-start;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .sketch-preview-close {
        top: 0;
        right: 0;
    }

    .sketch-preview-img-wrap {
        flex: 0 0 auto;
        max-height: calc(100dvh - 300px);
        margin-bottom: 0;
        padding: 8px;
    }

    #sketch-preview-img {
        max-height: 100%;
    }

    .sketch-preview-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        padding-bottom: 0;
        margin-top: auto;
        align-self: stretch;
    }

    .sp-btn {
        min-height: 58px;
        padding: 8px 4px;
        font-size: 11px;
        gap: 4px;
        flex-direction: column;
        line-height: 1.1;
    }

    .sp-btn svg {
        width: 16px;
        height: 16px;
    }
}

@media (max-width: 600px) and (pointer: coarse) and (orientation: portrait) {
    .sketch-preview-modal {
        /* Reduce unused dark area under actions on phones. */
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .sketch-preview-content {
        max-height: calc(100dvh - 8px);
        padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px));
        overflow: hidden;
    }

    .sketch-preview-img-wrap {
        flex: 1 1 auto;
        min-height: 0;
        max-height: calc(100dvh - 238px);
    }

    .sketch-preview-actions {
        gap: 5px;
        margin-top: auto;
        padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px));
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .sp-btn {
        min-height: 46px;
        padding: 7px 4px;
        font-size: 10px;
        gap: 3px;
    }

    .sp-btn svg {
        width: 15px;
        height: 15px;
    }

    .sketch-preview-actions .sp-btn:last-child {
        grid-column: 2;
    }
}

@media (max-width: 767px) and (orientation: portrait) {
    #qe-mobile-composer.tg-composer {
        z-index: 9000 !important;
    }

    #qe-layer-popover {
        position: fixed !important;
        z-index: 11000 !important;
        bottom: 8px !important;
        min-height: auto !important;
        max-height: calc(100vh - 120px) !important;
    }
}

/* Tablet landscape only: reduce vertical density and use dynamic viewport height */
@media (orientation: landscape) and (pointer: coarse) and (min-width: 901px) and (max-width: 1366px) {
    #qe-prompt-desktop.tg-sidebar-textarea {
        min-height: 84px !important;
        height: 84px !important;
    }
}

/* -------------------------------------------------------------------------- */
/* Brush Tools Visual Refresh (Sketch + Magic Blend)                          */
/* Visual only: segmented glass rail + modern active state                    */
/* -------------------------------------------------------------------------- */
.qe-tools-row {
    position: relative;
    gap: 0;
    padding: 3px;
    border-radius: 999px;
    border: 1px solid rgba(16, 185, 129, 0.34);
    background:
        linear-gradient(180deg, rgba(16, 185, 129, 0.12) 0%, rgba(255, 255, 255, 0.02) 100%),
        linear-gradient(180deg, rgba(7, 20, 34, 0.95) 0%, rgba(4, 13, 24, 0.95) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        inset 0 -1px 0 rgba(255, 255, 255, 0.05),
        0 10px 24px rgba(2, 6, 23, 0.4);
}

.qe-tool-btn {
    border-radius: 16px !important;
    border: 1px solid transparent !important;
    background: transparent !important;
    box-shadow: none !important;
    position: relative;
    overflow: hidden;
}

#btn-tool-marker.qe-tool-btn::after,
#btn-tool-eraser.qe-tool-btn::after,
#btn-tool-select.qe-tool-btn::after {
    content: "";
    position: absolute;
    top: 22%;
    bottom: 22%;
    right: -1px;
    width: 1px;
    background: rgba(16, 185, 129, 0.2);
}

#btn-tool-select.qe-tool-btn::after {
    display: none;
}

.qe-tool-btn svg,
.qe-tool-btn span {
    position: relative;
    z-index: 2;
}

.qe-tool-btn svg {
    width: 20px;
    height: 20px;
    color: rgba(236, 253, 245, 0.94);
    opacity: 0.98;
}

.qe-tool-btn.active {
    border-color: rgba(16, 185, 129, 0.66) !important;
    color: #f3fff9 !important;
    background:
        radial-gradient(120% 120% at 26% 16%, rgba(16, 185, 129, 0.35) 0%, rgba(16, 185, 129, 0) 62%),
        linear-gradient(180deg, rgba(16, 185, 129, 0.6) 0%, rgba(9, 91, 74, 0.66) 100%) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.35),
        0 0 18px rgba(34, 197, 94, 0.35) !important;
}

.qe-tool-btn.active svg {
    color: #f2fffb;
    filter: drop-shadow(0 2px 7px rgba(16, 185, 129, 0.34));
}

/* Mobile compact tool buttons (only marker / eraser / select) */
#btn-m-marker.btn-tool-mobile,
#btn-m-eraser.btn-tool-mobile,
#btn-ts-marker.qe-m-tool,
#btn-ts-eraser.qe-m-tool,
#btn-ts-select.qe-m-tool,
#mp-btn-ts-marker.qe-m-tool,
#mp-btn-ts-eraser.qe-m-tool,
#mp-btn-ts-select.qe-m-tool {
    border-radius: 12px;
    border: 1px solid rgba(16, 185, 129, 0.3) !important;
    background:
        linear-gradient(180deg, rgba(16, 185, 129, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%),
        linear-gradient(180deg, rgba(7, 20, 34, 0.94) 0%, rgba(4, 13, 24, 0.94) 100%) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        0 8px 14px rgba(2, 6, 23, 0.35);
}

#btn-m-marker.btn-tool-mobile svg,
#btn-m-eraser.btn-tool-mobile svg,
#btn-ts-marker.qe-m-tool svg,
#btn-ts-eraser.qe-m-tool svg,
#btn-ts-select.qe-m-tool svg,
#mp-btn-ts-marker.qe-m-tool svg,
#mp-btn-ts-eraser.qe-m-tool svg,
#mp-btn-ts-select.qe-m-tool svg {
    width: 18px;
    height: 18px;
    color: rgba(236, 253, 245, 0.94);
    opacity: 0.98;
}

#btn-m-marker.btn-tool-mobile.active,
#btn-m-eraser.btn-tool-mobile.active,
#btn-ts-marker.qe-m-tool.active,
#btn-ts-eraser.qe-m-tool.active,
#btn-ts-select.qe-m-tool.active,
#mp-btn-ts-marker.qe-m-tool.active,
#mp-btn-ts-eraser.qe-m-tool.active,
#mp-btn-ts-select.qe-m-tool.active {
    border-color: rgba(16, 185, 129, 0.62) !important;
    background:
        radial-gradient(120% 120% at 26% 16%, rgba(16, 185, 129, 0.3) 0%, rgba(16, 185, 129, 0) 60%),
        linear-gradient(180deg, rgba(16, 185, 129, 0.54) 0%, rgba(9, 91, 74, 0.6) 100%) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.26),
        0 0 14px rgba(16, 185, 129, 0.3);
}

#btn-m-marker.btn-tool-mobile.active svg,
#btn-m-eraser.btn-tool-mobile.active svg,
#btn-ts-marker.qe-m-tool.active svg,
#btn-ts-eraser.qe-m-tool.active svg,
#btn-ts-select.qe-m-tool.active svg,
#mp-btn-ts-marker.qe-m-tool.active svg,
#mp-btn-ts-eraser.qe-m-tool.active svg,
#mp-btn-ts-select.qe-m-tool.active svg {
    color: #f2fffb;
}

/* Final normalization: phone + iPad use identical Sketch strip visuals */
@media (max-width: 1024px) {
    .nav-container .brand+span {
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
        font-size: 0.72rem !important;
        max-width: 100% !important;
        display: inline-block !important;
    }

    #btn-generate-mobile {
        background: var(--neon-green) !important;
        color: #020617 !important;
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.4) !important;
        border: 1px solid var(--neon-green) !important;
        border-radius: 50% !important;
        width: 48px !important;
        height: 48px !important;
        flex: 0 0 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .qe-m-text-btn {
        flex-direction: column !important;
        gap: 2px !important;
        font-size: 8px !important;
        text-transform: uppercase !important;
        font-weight: 700 !important;
        line-height: 1 !important;
        color: var(--neon-green) !important;
        border-color: rgba(16, 185, 129, 0.3) !important;
        height: auto !important;
        padding: 4px 2px !important;
        min-height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #qe-mobile-tool-strip #qe-steps-input {
        width: 36px !important;
        height: 24px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid var(--glass-border) !important;
        border-radius: 4px !important;
        color: white !important;
        text-align: center !important;
        font-size: 16px !important;
        padding: 0 !important;
        appearance: none !important;
        -moz-appearance: textfield !important;
        scroll-margin: 0 !important;
        scroll-padding: 0 !important;
    }

    #qe-mobile-tool-strip #qe-steps-input:focus {
        border-color: var(--neon-green) !important;
        background: rgba(255, 255, 255, 0.1) !important;
        outline: none !important;
    }

    #qe-mobile-tool-strip #qe-steps-input::-webkit-inner-spin-button,
    #qe-mobile-tool-strip #qe-steps-input::-webkit-outer-spin-button {
        -webkit-appearance: none !important;
        margin: 0 !important;
    }

    #qe-mobile-tool-strip .qe-m-slider-container {
        height: 60px !important;
        width: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #qe-mobile-tool-strip .qe-m-slider {
        width: 60px !important;
        height: 20px !important;
        transform: rotate(-90deg) !important;
        transform-origin: center !important;
        -webkit-appearance: none !important;
        appearance: none !important;
    }

    #qe-mobile-tool-strip #btn-ts-marker,
    #qe-mobile-tool-strip #btn-ts-eraser,
    #qe-mobile-tool-strip #btn-ts-select,
    #qe-mobile-tool-strip #btn-m-marker,
    #qe-mobile-tool-strip #btn-m-eraser {
        border-radius: 12px !important;
        border: 1px solid rgba(16, 185, 129, 0.3) !important;
        background:
            linear-gradient(180deg, rgba(16, 185, 129, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%),
            linear-gradient(180deg, rgba(7, 20, 34, 0.94) 0%, rgba(4, 13, 24, 0.94) 100%) !important;
    }

    #qe-mobile-tool-strip #btn-ts-marker.active,
    #qe-mobile-tool-strip #btn-ts-eraser.active,
    #qe-mobile-tool-strip #btn-ts-select.active,
    #qe-mobile-tool-strip #btn-m-marker.active,
    #qe-mobile-tool-strip #btn-m-eraser.active {
        border-color: rgba(16, 185, 129, 0.62) !important;
        background:
            radial-gradient(120% 120% at 26% 16%, rgba(16, 185, 129, 0.3) 0%, rgba(16, 185, 129, 0) 60%),
            linear-gradient(180deg, rgba(16, 185, 129, 0.54) 0%, rgba(9, 91, 74, 0.6) 100%) !important;
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.26),
            0 0 14px rgba(16, 185, 129, 0.3) !important;
    }
}

