:root {
            --bg-studio: #08090d;
            --bg-canvas: #0e1118;
            --surface-01: #12151f;
            --surface-02: #181c2a;
            --surface-03: #22273a;
            --surface-glass: rgba(18, 21, 31, 0.88);
            --surface-glass-border: rgba(255, 255, 255, 0.08);

            --primary: #3b82f6;
            --primary-hover: #60a5fa;
            --primary-active: #2563eb;
            --primary-subtle: rgba(59, 130, 246, 0.12);
            --primary-glow: rgba(59, 130, 246, 0.28);

            --accent-emerald: #10b981;
            --accent-emerald-subtle: rgba(16, 185, 129, 0.14);
            --accent-rose: #f43f5e;
            --accent-rose-subtle: rgba(244, 63, 94, 0.14);

            --text-primary: #f8fafc;
            --text-secondary: #94a3b8;
            --text-muted: #64748b;
            --border-subtle: rgba(255, 255, 255, 0.08);
            --border-strong: rgba(255, 255, 255, 0.16);
            --border-highlight: rgba(59, 130, 246, 0.4);

            --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
            --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
            --font-mono: 'JetBrains Mono', monospace;

            --sat: env(safe-area-inset-top, 0px);
            --sab: env(safe-area-inset-bottom, 0px);
            --sal: env(safe-area-inset-left, 0px);
            --sar: env(safe-area-inset-right, 0px);

            --radius-sm: 8px;
            --radius-md: 12px;
            --radius-lg: 16px;
            --radius-xl: 24px;
            --radius-pill: 9999px;
            --touch-min: 44px;
        }

        * {
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
            margin: 0;
            padding: 0;
            user-select: none;
            -webkit-user-select: none;
        }

        button:focus-visible,
        label:focus-visible,
        select:focus-visible,
        input:focus-visible,
        .layer-chip:focus-visible,
        .ratio-pill:focus-visible,
        .pill-btn:focus-visible,
        [tabindex="0"]:focus-visible {
            outline: 2px solid var(--primary);
            outline-offset: 2px;
        }

        html, body {
            width: 100%;
            height: 100dvh;
            min-height: -webkit-fill-available;
            overflow: hidden;
            background-color: var(--bg-studio);
            color: var(--text-primary);
            font-family: var(--font-body);
            touch-action: manipulation;
        }

        /* Subtle Studio Ambient Radial Lighting */
        body::before {
            content: '';
            position: fixed;
            top: 20%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: min(800px, 120vw);
            height: min(800px, 120vw);
            background: radial-gradient(circle, rgba(59, 130, 246, 0.05) 0%, rgba(18, 21, 31, 0.02) 50%, transparent 75%);
            pointer-events: none;
            z-index: 0;
        }

        body {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            position: relative;
        }

        /* Top Dynamic Toast Notification */
        .toast {
            position: fixed;
            top: calc(var(--sat) + 68px);
            left: 50%;
            transform: translateX(-50%) translateY(-120px);
            opacity: 0;
            background: rgba(18, 21, 31, 0.94);
            backdrop-filter: blur(24px);
            -webkit-backdrop-filter: blur(24px);
            color: var(--text-primary);
            font-family: var(--font-body);
            font-size: 13px;
            font-weight: 600;
            padding: 10px 20px;
            border-radius: var(--radius-pill);
            border: 1px solid var(--border-strong);
            box-shadow: 0 16px 36px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.06);
            display: flex;
            align-items: center;
            gap: 10px;
            z-index: 350;
            pointer-events: none;
            transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
            max-width: 90vw;
            text-align: center;
        }

        .toast.visible {
            transform: translateX(-50%) translateY(0);
            opacity: 1;
        }

        .toast-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
        }

        /* Header Navigation Bar */
        .app-header {
            width: 100%;
            padding-top: calc(var(--sat) + 8px);
            padding-bottom: 10px;
            padding-left: max(16px, var(--sal));
            padding-right: max(16px, var(--sar));
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: var(--surface-glass);
            backdrop-filter: blur(24px);
            -webkit-backdrop-filter: blur(24px);
            border-bottom: 1px solid var(--border-subtle);
            z-index: 50;
            flex-shrink: 0;
        }

        .brand-group {
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
        }

        .brand-logo-icon {
            width: 34px;
            height: 34px;
            border-radius: 10px;
            background: linear-gradient(135deg, #1e2638, #121622);
            border: 1px solid rgba(255, 255, 255, 0.12);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
            flex-shrink: 0;
        }

        .brand-logo-icon svg {
            width: 20px;
            height: 20px;
        }

        .app-title {
            font-family: var(--font-display);
            font-size: 17px;
            font-weight: 700;
            letter-spacing: -0.3px;
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--text-primary);
        }

        .version-tag {
            font-family: var(--font-mono);
            font-size: 9.5px;
            font-weight: 700;
            background: var(--primary-subtle);
            color: var(--primary-hover);
            border: 1px solid rgba(59, 130, 246, 0.3);
            padding: 2px 6px;
            border-radius: 6px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .header-actions {
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .hud-badge {
            font-family: var(--font-mono);
            font-size: 11px;
            font-weight: 600;
            color: var(--text-secondary);
            background: var(--surface-02);
            padding: 5px 10px;
            border-radius: var(--radius-pill);
            border: 1px solid var(--border-subtle);
            display: flex;
            align-items: center;
            gap: 5px;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .hud-badge-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: var(--accent-emerald);
            box-shadow: 0 0 6px var(--accent-emerald);
        }

        .btn-icon-hud {
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            color: var(--text-secondary);
            width: 38px;
            height: 38px;
            min-width: var(--touch-min);
            min-height: var(--touch-min);
            border-radius: 10px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
            position: relative;
            touch-action: manipulation;
        }

        .btn-icon-hud svg {
            width: 18px;
            height: 18px;
            stroke-width: 2;
        }

        .btn-icon-hud:active {
            color: var(--text-primary);
            border-color: var(--primary);
            background: var(--surface-03);
            transform: scale(0.95);
        }

        .btn-icon-hud:disabled {
            opacity: 0.3;
            cursor: not-allowed;
            pointer-events: none;
            border-color: var(--border-subtle);
            color: var(--text-muted);
        }

        /* Layer Selector Strip */
        .layer-strip {
            width: 100%;
            max-width: 680px;
            padding: 8px 16px;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            gap: 8px;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
            background: rgba(15, 18, 27, 0.88);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-bottom: 1px solid var(--border-subtle);
            z-index: 40;
            flex-shrink: 0;
            transition: all 0.25s ease;
        }
        .layer-strip::-webkit-scrollbar {
            display: none;
        }
        .layer-strip.hidden {
            display: none;
        }
        .layer-strip-title {
            font-family: var(--font-mono);
            font-size: 10px;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            font-weight: 700;
            color: var(--text-muted);
            margin-right: 6px;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        .layer-strip-count {
            display: inline-flex;
            align-items: center;
            padding: 1px 5px;
            border-radius: 4px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.12);
            color: var(--text-secondary);
            font-family: var(--font-mono);
            font-size: 9.5px;
            font-weight: 600;
            letter-spacing: 0;
        }

        .layer-chip {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 12px 6px 6px;
            min-height: var(--touch-min);
            border-radius: var(--radius-md);
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            cursor: pointer;
            flex-shrink: 0;
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
        }
        .layer-chip:active {
            transform: scale(0.96);
        }
        .layer-chip.active {
            border-color: var(--primary);
            background: var(--primary-subtle);
            box-shadow: 0 0 0 1px var(--primary);
        }
        .layer-chip-thumb {
            width: 32px;
            height: 32px;
            border-radius: 7px;
            object-fit: cover;
            background: #000000;
            border: 1px solid rgba(255, 255, 255, 0.12);
            display: block;
        }
        .layer-chip-name {
            font-family: var(--font-body);
            font-size: 12px;
            font-weight: 600;
            color: var(--text-primary);
            max-width: 80px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .layer-chip-badge {
            font-family: var(--font-mono);
            font-size: 9.5px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.12);
            color: var(--text-secondary);
            padding: 1px 6px;
            border-radius: 4px;
            display: inline-flex;
            align-items: center;
            gap: 3px;
        }
        .layer-chip-num {
            min-width: 20px;
            height: 20px;
            padding: 0 3px;
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.15);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-family: var(--font-mono);
            font-size: 9.5px;
            font-weight: 700;
            font-variant-numeric: tabular-nums;
            color: var(--text-secondary);
            flex-shrink: 0;
            box-sizing: border-box;
        }
        .layer-chip.active .layer-chip-num {
            background: var(--primary);
            border-color: var(--primary);
            color: #ffffff;
            box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
        }

        .layer-drag-handle {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 20px;
            height: 20px;
            color: var(--text-muted);
            cursor: grab;
            flex-shrink: 0;
            touch-action: none;
            transition: color 0.15s ease;
        }
        .layer-drag-handle:hover {
            color: var(--text-primary);
        }
        .layer-drag-handle:active {
            cursor: grabbing;
        }
        .layer-item-row.dragging {
            opacity: 0.4;
            border-style: dashed;
        }
        .layer-item-row.drag-over {
            border-color: var(--primary);
            background: var(--primary-subtle);
            box-shadow: 0 0 0 1px var(--primary);
        }
        .layer-chip-add {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
            padding: 6px;
            width: var(--touch-min);
            min-width: var(--touch-min);
            min-height: var(--touch-min);
            border-radius: var(--radius-md);
            background: rgba(255, 255, 255, 0.04);
            border: 1px dashed var(--border-strong);
            color: var(--text-secondary);
            font-family: var(--font-body);
            font-size: 11.5px;
            font-weight: 600;
            cursor: pointer;
            flex-shrink: 0;
            transition: all 0.2s ease;
        }
        .layer-chip-add svg {
            width: 13px;
            height: 13px;
            color: var(--primary);
        }
        .layer-chip-add:hover {
            color: var(--primary);
            border-color: var(--primary);
            background: var(--primary-subtle);
        }
        .layer-chip-add:active {
            transform: scale(0.96);
        }

        /* Layers Panel Bottom Drawer */
        .layers-panel {
            max-height: 80vh;
            gap: 14px;
        }

        .layers-panel-actions {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            width: 100%;
        }

        .btn-mosaic-action {
            background: var(--surface-02);
            color: var(--text-primary);
            border-color: var(--border-subtle);
        }
        .btn-mosaic-action:hover:not(:disabled) {
            background: var(--surface-03);
            border-color: var(--border-strong);
            color: #ffffff;
        }
        .btn-mosaic-action:active:not(:disabled),
        .btn-mosaic-action.active {
            background: var(--primary-subtle);
            border-color: var(--primary);
            color: var(--primary-hover);
        }

        .mosaic-options-wrapper {
            display: flex;
            flex-direction: column;
            gap: 8px;
            background: rgba(255, 255, 255, 0.03);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
            padding: 10px;
            margin-top: -4px;
        }
        .mosaic-options-wrapper.hidden {
            display: none !important;
        }
        .mosaic-options-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .mosaic-options-title {
            font-family: var(--font-mono);
            font-size: 10px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            color: var(--text-muted);
        }

        .mosaic-preset-grid {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 6px;
        }
        @media (max-width: 440px) {
            .mosaic-preset-grid {
                grid-template-columns: repeat(5, 1fr);
                gap: 4px;
            }
        }
        .btn-mosaic-preset {
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-sm);
            padding: 8px 4px;
            min-height: 44px;
            color: var(--text-secondary);
            font-family: var(--font-body);
            font-size: 11px;
            font-weight: 600;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 4px;
            cursor: pointer;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
            user-select: none;
            -webkit-user-select: none;
            touch-action: manipulation;
        }
        .btn-mosaic-preset svg {
            width: 16px;
            height: 16px;
            color: var(--primary);
        }
        .btn-mosaic-preset:hover,
        .btn-mosaic-preset:focus-visible {
            background: var(--surface-03);
            color: var(--text-primary);
            border-color: var(--border-strong);
        }
        .btn-mosaic-preset:active,
        .btn-mosaic-preset.active {
            border-color: var(--primary);
            background: var(--primary-subtle);
            color: var(--primary-hover);
            transform: scale(0.96);
        }

        .btn-panel-action {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 10px 14px;
            border-radius: var(--radius-md);
            font-family: var(--font-body);
            font-size: 13px;
            font-weight: 600;
            min-height: var(--touch-min);
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            touch-action: manipulation;
            border: 1px solid var(--border-subtle);
        }
        .btn-panel-action:disabled,
        .btn-panel-action[aria-disabled="true"] {
            opacity: 0.45;
            cursor: not-allowed;
            pointer-events: none;
            box-shadow: none !important;
        }

        .btn-panel-action svg {
            width: 16px;
            height: 16px;
            flex-shrink: 0;
        }

        .btn-add-layer {
            background: linear-gradient(135deg, #2563eb, #1d4ed8);
            border-color: rgba(59, 130, 246, 0.45);
            color: #ffffff;
            box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
        }
        .btn-add-layer:hover {
            background: linear-gradient(135deg, #3b82f6, #2563eb);
            border-color: #60a5fa;
            transform: translateY(-1px);
        }
        .btn-add-layer:active {
            transform: scale(0.97);
            background: #1d4ed8;
        }

        .btn-reset-workspace {
            background: var(--surface-02);
            color: var(--text-primary);
            border-color: var(--border-subtle);
        }
        .btn-reset-workspace:hover:not(:disabled) {
            background: var(--surface-03);
            border-color: var(--border-strong);
            color: #ffffff;
        }
        .btn-reset-workspace:active:not(:disabled) {
            transform: scale(0.97);
        }
        .btn-reset-workspace:disabled {
            opacity: 0.4;
            cursor: not-allowed;
        }

        .layers-list-wrapper {
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-height: 48vh;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            padding: 2px 0;
        }

        .layer-item-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 6px;
            padding: 6px 8px 6px 4px;
            background: var(--surface-02);
            border: 1.5px solid var(--border-subtle);
            border-radius: var(--radius-md);
            cursor: pointer;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
            user-select: none;
            -webkit-user-select: none;
            min-height: var(--touch-min);
        }
        .layer-item-row:hover {
            background: var(--surface-03);
            border-color: var(--border-strong);
        }
        .layer-item-row.active {
            border-color: var(--primary);
            background: var(--primary-subtle);
            box-shadow: 0 0 0 1px var(--primary);
        }

        .layer-item-num {
            min-width: 22px;
            height: 22px;
            padding: 0 4px;
            border-radius: 11px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.15);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-family: var(--font-mono);
            font-size: 10px;
            font-weight: 700;
            color: var(--text-secondary);
            flex-shrink: 0;
        }
        .layer-item-row.active .layer-item-num {
            background: var(--primary);
            border-color: var(--primary);
            color: #ffffff;
            box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
        }

        .layer-item-thumb {
            width: 40px;
            height: 40px;
            border-radius: 8px;
            object-fit: cover;
            background: #000000;
            border: 1px solid rgba(255, 255, 255, 0.12);
            display: block;
            flex-shrink: 0;
        }

        .layer-item-info {
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 2px;
            min-width: 0;
            text-align: left;
        }

        .layer-item-title-row {
            display: flex;
            align-items: center;
            gap: 8px;
            justify-content: flex-start;
        }

        .layer-item-name {
            font-family: var(--font-body);
            font-size: 13px;
            font-weight: 600;
            color: var(--text-primary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            text-align: left;
        }

        .layer-item-badge {
            font-family: var(--font-mono);
            font-size: 9.5px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.12);
            color: var(--text-secondary);
            padding: 1px 6px;
            border-radius: 4px;
            display: inline-flex;
            align-items: center;
            gap: 3px;
        }

        .layer-item-actions {
            display: flex;
            align-items: center;
            gap: 4px;
            margin-left: auto;
            flex-shrink: 0;
        }

        .btn-layer-toggle {
            width: 32px;
            height: 32px;
            min-width: 32px;
            min-height: 32px;
            border-radius: 8px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: transparent;
            border: 1px solid transparent;
            color: var(--text-muted);
            cursor: pointer;
            transition: all 0.15s ease;
            flex-shrink: 0;
            padding: 0;
        }
        .btn-layer-toggle:hover,
        .btn-layer-toggle:focus-visible {
            color: var(--text-primary);
            background: var(--surface-03);
            border-color: var(--border-subtle);
        }
        .btn-layer-toggle.active {
            color: var(--primary-hover);
            background: var(--primary-subtle);
            border-color: rgba(59, 130, 246, 0.3);
        }
        .btn-layer-toggle svg {
            width: 15px;
            height: 15px;
        }

        .btn-layer-duplicate {
            width: 32px;
            height: 32px;
            min-width: 32px;
            min-height: 32px;
            border-radius: 8px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: transparent;
            border: 1px solid transparent;
            color: var(--text-muted);
            cursor: pointer;
            transition: all 0.15s ease;
            flex-shrink: 0;
            padding: 0;
        }
        .btn-layer-duplicate:hover,
        .btn-layer-duplicate:focus-visible {
            color: var(--primary-hover);
            background: var(--primary-subtle);
            border-color: rgba(59, 130, 246, 0.25);
        }
        .btn-layer-duplicate svg {
            width: 15px;
            height: 15px;
        }

        .btn-layer-delete {
            width: 32px;
            height: 32px;
            min-width: 32px;
            min-height: 32px;
            border-radius: 8px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: transparent;
            border: 1px solid transparent;
            color: var(--text-muted);
            cursor: pointer;
            transition: all 0.15s ease;
            flex-shrink: 0;
            padding: 0;
        }
        .btn-layer-delete:hover,
        .btn-layer-delete:focus-visible {
            color: var(--accent-rose);
            background: var(--accent-rose-subtle);
            border-color: rgba(244, 63, 94, 0.25);
        }
        .btn-layer-delete svg {
            width: 15px;
            height: 15px;
        }

        .layers-empty-state {
            padding: 32px 16px;
            text-align: center;
            color: var(--text-muted);
            font-size: 13px;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
        }
        .layers-empty-state svg {
            width: 32px;
            height: 32px;
            color: var(--text-muted);
            opacity: 0.5;
        }

        /* Canvas Workspace Area */
        .workspace {
            flex: 1;
            width: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            padding: 12px;
            overflow: hidden;
            position: relative;
        }

        .canvas-card {
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.08);
            background-color: var(--bg-canvas);
            background-image:
                linear-gradient(45deg, #131722 25%, transparent 25%),
                linear-gradient(-45deg, #131722 25%, transparent 25%),
                linear-gradient(45deg, transparent 75%, #131722 75%),
                linear-gradient(-45deg, transparent 75%, #131722 75%);
            background-size: 18px 18px;
            background-position: 0 0, 0 9px, 9px -9px, -9px 0px;
            position: relative;
            touch-action: none;
            transition: border-color 0.25s ease;
            aspect-ratio: 1 / 1;
            max-width: 100%;
            max-height: 100%;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .canvas-container {
            margin: 0 auto !important;
            max-width: 100% !important;
            max-height: 100% !important;
        }

        .canvas-card canvas {
            max-width: 100%;
            max-height: 100%;
        }

        /* Canvas HUD Info Bar */
        .canvas-hud-overlay {
            position: absolute;
            top: 10px;
            left: 12px;
            right: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            pointer-events: none;
            z-index: 10;
        }
        .hud-pill {
            font-family: var(--font-mono);
            font-size: 10.5px;
            background: rgba(15, 18, 27, 0.85);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            color: var(--text-secondary);
            padding: 3px 10px;
            border-radius: var(--radius-sm);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .hud-select {
            font-family: var(--font-mono);
            font-size: 10.5px;
            font-weight: 600;
            background: rgba(15, 18, 27, 0.85);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            color: var(--text-primary);
            padding: 3px 8px;
            border-radius: var(--radius-sm);
            border: 1px solid rgba(255, 255, 255, 0.15);
            outline: none;
            cursor: pointer;
            pointer-events: auto;
        }
        .hud-select:focus-visible {
            border-color: var(--primary);
        }

        /* Empty Canvas Prompt */
        .empty-canvas-prompt {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 12px;
            color: var(--text-secondary);
            pointer-events: auto;
            cursor: pointer;
            text-align: center;
            width: 88%;
            max-width: 320px;
            padding: 16px;
            transition: opacity 0.2s ease;
            z-index: 5;
        }
        .empty-canvas-prompt.hidden {
            opacity: 0;
            display: none;
        }
        .empty-canvas-icon {
            width: 52px;
            height: 52px;
            border-radius: 16px;
            background: var(--surface-02);
            border: 1px dashed rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
        }
        .empty-canvas-icon svg {
            width: 24px;
            height: 24px;
        }
        .empty-canvas-title {
            font-family: var(--font-display);
            font-size: 15px;
            font-weight: 700;
            color: var(--text-primary);
        }
        .empty-canvas-text {
            font-size: 12.5px;
            line-height: 1.5;
            color: var(--text-secondary);
            max-width: 260px;
        }
        /* Privacy Badge Pill (Canvas Empty State) */
        .privacy-badge-pill {
            display: inline-flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            padding: 6px 14px;
            background: rgba(16, 185, 129, 0.08);
            border: 1px solid rgba(16, 185, 129, 0.28);
            border-radius: var(--radius-pill);
            color: #10b981;
            font-size: 11.5px;
            font-weight: 600;
            letter-spacing: 0.01em;
            margin-top: 6px;
            margin-bottom: 2px;
            cursor: pointer;
            transition: all 0.2s ease;
            pointer-events: auto;
            text-align: center;
        }
        .privacy-badge-header {
            display: inline-flex;
            align-items: center;
            gap: 5px;
        }
        .privacy-badge-pill svg {
            width: 14px;
            height: 14px;
            color: #10b981;
            flex-shrink: 0;
        }
        .privacy-badge-pill:hover {
            background: rgba(16, 185, 129, 0.16);
            border-color: #10b981;
            transform: translateY(-1px);
        }
        .privacy-badge-pill:active {
            transform: scale(0.98);
        }

        /* Subordinated Demo Buttons */
        .btn-demo-subtle {
            pointer-events: auto;
            margin-top: 2px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            padding: 7px 14px;
            min-height: 38px;
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-pill);
            color: var(--text-secondary);
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            touch-action: manipulation;
        }
        .btn-demo-subtle svg {
            width: 14px;
            height: 14px;
            color: var(--primary);
            opacity: 0.85;
            flex-shrink: 0;
        }
        .btn-demo-subtle:hover {
            color: var(--text-primary);
            border-color: var(--primary);
            background: var(--surface-03);
            transform: translateY(-1px);
        }
        .btn-demo-subtle:active {
            transform: scale(0.97);
        }

        .btn-demo-prompt {
            pointer-events: auto;
            margin-top: 4px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 7px;
            padding: 9px 18px;
            min-height: 42px;
            background: var(--surface-02);
            border: 1px solid var(--border-strong);
            border-radius: var(--radius-pill);
            color: #ffffff;
            font-size: 12.5px;
            font-weight: 600;
            cursor: pointer;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            touch-action: manipulation;
        }
        .btn-demo-prompt svg {
            width: 15px;
            height: 15px;
            color: var(--primary);
        }
        .btn-demo-prompt:hover {
            background: var(--surface-03);
            border-color: var(--primary);
            transform: translateY(-1px);
        }
        .btn-demo-prompt:active {
            transform: scale(0.96);
        }

        /* Unified Bottom Toolbar: Context Bar */
        .context-bar {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            gap: 6px;
            overflow-x: auto;
            scrollbar-width: none;
            flex: 1;
            min-width: 0;
            padding: 0 2px;
            transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
        }
        .context-bar::-webkit-scrollbar {
            display: none;
        }

        .context-bar.disabled {
            opacity: 0.35;
        }

        .btn-layer-tool {
            background: var(--surface-02);
            color: var(--text-primary);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
            padding: 8px 12px;
            font-family: var(--font-body);
            font-size: 12px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 6px;
            cursor: pointer;
            justify-content: center;
            min-height: 48px;
            height: 48px;
            white-space: nowrap;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
            flex-shrink: 0;
        }
        .btn-layer-tool svg {
            width: 16px;
            height: 16px;
            flex-shrink: 0;
        }
        .btn-layer-tool:active {
            background: var(--surface-03);
            border-color: var(--primary);
            transform: scale(0.96);
        }
        .btn-layer-tool.btn-accent {
            color: var(--primary-hover);
            border-color: rgba(59, 130, 246, 0.35);
            background: var(--primary-subtle);
        }
        .btn-layer-tool:disabled {
            opacity: 0.4;
            cursor: not-allowed;
            pointer-events: none;
        }
        .btn-layer-tool.btn-delete {
            color: var(--accent-rose);
            border-color: rgba(244, 63, 94, 0.25);
        }
        .btn-layer-tool.btn-delete:active {
            background: var(--accent-rose-subtle);
        }

        /* Bottom Thumb Action Dock */
        .bottom-dock {
            width: 100%;
            background: rgba(15, 18, 27, 0.92);
            backdrop-filter: blur(28px);
            -webkit-backdrop-filter: blur(28px);
            padding-top: 10px;
            padding-bottom: calc(var(--sab) + 12px);
            padding-left: max(12px, var(--sal));
            padding-right: max(12px, var(--sar));
            border-top: 1px solid var(--border-subtle);
            display: flex;
            gap: 8px;
            justify-content: space-between;
            align-items: center;
            z-index: 50;
            flex-shrink: 0;
            max-width: 680px;
            box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.6);
        }

        .btn-dock {
            min-height: 48px;
            height: 48px;
            border-radius: var(--radius-md);
            font-family: var(--font-body);
            font-size: 13.5px;
            font-weight: 600;
            letter-spacing: -0.1px;
            border: 1px solid var(--border-subtle);
            background: var(--surface-02);
            color: var(--text-primary);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            cursor: pointer;
            flex-shrink: 0;
            padding: 0 14px;
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            user-select: none;
            -webkit-user-select: none;
            touch-action: manipulation;
            position: relative;
            white-space: nowrap;
        }

        .btn-dock svg {
            flex-shrink: 0;
            width: 18px;
            height: 18px;
        }

        .btn-dock:active {
            transform: scale(0.97);
            background: var(--surface-03);
        }

        .btn-dock.icon-only {
            padding: 0;
            width: 48px;
            min-width: 48px;
        }

        .btn-dock.icon-only span {
            display: none;
        }

        .btn-load-photo,
        .btn-layers {
            background: linear-gradient(135deg, #2563eb, #1d4ed8);
            border-color: rgba(59, 130, 246, 0.45);
            color: #ffffff;
            box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
        }
        .btn-load-photo:hover,
        .btn-layers:hover {
            background: linear-gradient(135deg, #3b82f6, #2563eb);
            border-color: #60a5fa;
            transform: translateY(-1px);
        }
        .btn-load-photo:active,
        .btn-layers:active {
            transform: scale(0.97);
            background: #1d4ed8;
        }
        .btn-load-photo svg,
        .btn-layers svg {
            color: #ffffff;
        }

        .btn-paste {
            background: var(--primary-subtle);
            border-color: rgba(59, 130, 246, 0.35);
            color: #ffffff;
        }
        .btn-paste:active {
            background: rgba(59, 130, 246, 0.22);
            border-color: var(--primary);
        }
        .btn-paste svg {
            color: var(--primary-hover);
        }

        .btn-add {
            background: var(--surface-02);
            border-color: var(--border-strong);
            color: var(--text-primary);
        }
        .btn-add:active {
            background: var(--surface-03);
        }
        .btn-add svg {
            color: var(--text-secondary);
        }

        .btn-export {
            background: var(--accent-emerald-subtle);
            border-color: rgba(16, 185, 129, 0.35);
            color: var(--accent-emerald);
        }
        .btn-export:active {
            background: rgba(16, 185, 129, 0.24);
            border-color: var(--accent-emerald);
        }
        .btn-export svg {
            color: var(--accent-emerald);
        }

        .btn-export.disabled,
        .btn-export:disabled {
            opacity: 0.35;
            background: rgba(255, 255, 255, 0.03);
            border-color: var(--border-subtle);
            color: var(--text-muted);
            box-shadow: none;
            cursor: not-allowed;
            pointer-events: none;
        }
        .btn-export.disabled svg,
        .btn-export:disabled svg {
            color: var(--text-muted);
        }

        /* Native iOS Bottom Sheet for Adjustments & Filters */
        .drawer-overlay {
            position: fixed;
            inset: 0;
            background: rgba(4, 5, 8, 0.75);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            z-index: 200;
            display: flex;
            align-items: flex-end;
            justify-content: center;
            opacity: 1;
            transition: opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .drawer-overlay.hidden {
            display: none;
            opacity: 0;
            pointer-events: none;
        }
        .drawer-overlay.closing {
            opacity: 0;
            pointer-events: none;
        }
        .drawer-overlay.closing .drawer-panel {
            transform: translateY(100%);
            transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .drawer-panel {
            width: 100%;
            max-width: 600px;
            max-height: 82vh;
            background: var(--surface-01);
            border-radius: 24px 24px 0 0;
            border-top: 1px solid var(--border-strong);
            border-left: 1px solid var(--border-subtle);
            border-right: 1px solid var(--border-subtle);
            box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.8);
            display: flex;
            flex-direction: column;
            padding: 12px 18px calc(var(--sab) + 20px) 18px;
            gap: 16px;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            transform: translateY(0);
            transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
            will-change: transform;
            touch-action: pan-y;
            animation: drawerSlideUp 0.22s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .drawer-panel.swiping {
            transition: none !important;
        }
        @keyframes drawerSlideUp {
            from { transform: translateY(100%); }
            to { transform: translateY(0); }
        }
        .drawer-grabber {
            width: 38px;
            height: 4.5px;
            border-radius: var(--radius-pill);
            background: rgba(255, 255, 255, 0.28);
            margin: 0 auto 4px auto;
            flex-shrink: 0;
            cursor: grab;
            touch-action: none;
        }
        .drawer-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--border-subtle);
            padding-bottom: 12px;
            flex-shrink: 0;
        }
        .drawer-title {
            font-family: var(--font-display);
            font-size: 16px;
            font-weight: 700;
            color: var(--text-primary);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .drawer-title svg {
            width: 18px;
            height: 18px;
            color: var(--primary);
        }
        .btn-close-drawer {
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            color: var(--text-secondary);
            width: 34px;
            height: 34px;
            min-width: var(--touch-min);
            min-height: var(--touch-min);
            border-radius: 10px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s ease;
        }
        .btn-close-drawer svg {
            width: 16px;
            height: 16px;
        }
        .btn-close-drawer:active {
            background: var(--surface-03);
            color: var(--text-primary);
        }

        /* Segmented Navigation Tabs in Drawer */
        .drawer-tabs {
            display: flex;
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
            padding: 3px;
            gap: 2px;
            flex-shrink: 0;
        }
        .drawer-tab {
            flex: 1;
            padding: 7px 10px;
            min-height: 36px;
            border-radius: 8px;
            background: transparent;
            border: none;
            color: var(--text-secondary);
            font-family: var(--font-body);
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
        }
        .drawer-tab.active {
            background: var(--surface-03);
            color: var(--text-primary);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
            border: 1px solid rgba(255, 255, 255, 0.08);
        }
        .tab-content {
            display: flex;
            flex-direction: column;
            gap: 16px;
        }
        .tab-content.hidden {
            display: none !important;
        }

        /* Controls inside Drawer */
        .control-group {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .control-label {
            font-family: var(--font-mono);
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            color: var(--text-secondary);
            display: flex;
            justify-content: space-between;
        }
        .control-value {
            color: var(--primary-hover);
        }
        .cyber-slider {
            -webkit-appearance: none;
            appearance: none;
            width: 100%;
            height: 6px;
            border-radius: 3px;
            background: var(--surface-03);
            outline: none;
            touch-action: pan-y;
        }
        .cyber-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background: #ffffff;
            border: 2px solid var(--primary);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
            cursor: pointer;
        }

        .cyber-select {
            background: var(--surface-02);
            color: var(--text-primary);
            border: 1px solid var(--border-subtle);
            padding: 10px 12px;
            min-height: var(--touch-min);
            border-radius: var(--radius-md);
            font-family: var(--font-body);
            font-size: 13px;
            outline: none;
        }

        .preset-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
        }
        .btn-preset {
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
            padding: 12px;
            min-height: 48px;
            color: var(--text-primary);
            font-family: var(--font-body);
            font-size: 12px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
        }
        .btn-preset svg {
            width: 16px;
            height: 16px;
            color: var(--primary);
        }
        .btn-preset:active,
        .btn-preset.active {
            border-color: var(--primary);
            background: var(--surface-03);
            box-shadow: 0 0 0 1px var(--primary);
            transform: scale(0.97);
        }
        .btn-preset:disabled,
        .btn-preset[aria-disabled="true"] {
            opacity: 0.45;
            cursor: not-allowed;
            pointer-events: none;
            transform: none !important;
            box-shadow: none !important;
        }

        /* Transparency & Background Knockout Controls */
        .drawer-section {
            display: flex;
            flex-direction: column;
            gap: 12px;
            background: rgba(255, 255, 255, 0.02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-lg);
            padding: 14px;
        }
        .drawer-section-title {
            font-family: var(--font-display);
            font-size: 13px;
            font-weight: 700;
            color: var(--text-primary);
            letter-spacing: 0.3px;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .drawer-section-title svg {
            width: 15px;
            height: 15px;
            color: var(--primary);
        }
        .transparency-knockout-box {
            background: rgba(0, 0, 0, 0.3);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
            padding: 12px;
            margin-top: 4px;
        }
        .toggle-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }
        .toggle-label {
            display: flex;
            flex-direction: column;
            gap: 2px;
            cursor: pointer;
        }
        .toggle-title {
            font-family: var(--font-body);
            font-size: 13px;
            font-weight: 600;
            color: #f1f5f9;
        }
        .toggle-desc {
            font-family: var(--font-body);
            font-size: 11.5px;
            color: var(--text-muted);
        }
        .cyber-switch {
            width: 46px;
            height: 26px;
            appearance: none;
            -webkit-appearance: none;
            background: var(--surface-03);
            border: 1px solid var(--border-strong);
            border-radius: var(--radius-pill);
            position: relative;
            cursor: pointer;
            outline: none;
            transition: all 0.2s ease;
            flex-shrink: 0;
        }
        .cyber-switch:checked {
            background: var(--primary);
            border-color: var(--primary-hover);
        }
        .cyber-switch::after {
            content: '';
            position: absolute;
            top: 2px;
            left: 2px;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: #ffffff;
            transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
        }
        .cyber-switch:checked::after {
            transform: translateX(20px);
        }
        .remove-color-details {
            margin-top: 12px;
            padding-top: 12px;
            border-top: 1px solid var(--border-subtle);
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .remove-color-details.hidden {
            display: none !important;
        }
        .color-picker-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }
        .control-sublabel {
            font-family: var(--font-body);
            font-size: 12px;
            color: var(--text-secondary);
        }
        .color-options {
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .btn-color-preset {
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-sm);
            padding: 5px 10px;
            font-family: var(--font-body);
            font-size: 11.5px;
            font-weight: 600;
            color: var(--text-primary);
            cursor: pointer;
            transition: all 0.15s ease;
            min-height: 32px;
        }
        .btn-color-preset:hover,
        .btn-color-preset.active {
            border-color: var(--primary);
            color: #ffffff;
            background: var(--primary-subtle);
        }
        #removeColorPicker {
            appearance: none;
            -webkit-appearance: none;
            border: 1px solid var(--border-strong);
            width: 32px;
            height: 32px;
            border-radius: var(--radius-sm);
            background: transparent;
            cursor: pointer;
            padding: 0;
            overflow: hidden;
        }
        #removeColorPicker::-webkit-color-swatch-wrapper {
            padding: 0;
        }
        #removeColorPicker::-webkit-color-swatch {
            border: none;
            border-radius: 7px;
        }

        /* Color Swatches and Draw Tool Styling */
        .color-swatch-row {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: nowrap;
            overflow-x: auto;
            scrollbar-width: none;
            padding: 4px 6px;
            width: 100%;
        }
        .color-swatch-row::-webkit-scrollbar {
            display: none;
        }
        .btn-color-swatch {
            width: 30px;
            height: 30px;
            min-width: 30px;
            min-height: 30px;
            padding: 0;
            border-radius: 8px;
            border: 1px solid var(--border-strong);
            cursor: pointer;
            flex-shrink: 0;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
            position: relative;
        }
        .btn-color-swatch#drawTransparentBtn {
            background: repeating-conic-gradient(#333 0% 25%, #666 0% 50%) 50% / 8px 8px;
        }
        .btn-color-swatch:hover {
            transform: translateY(-1px) scale(1.05);
            border-color: #ffffff;
        }
        .btn-color-swatch:active,
        .btn-color-swatch.active {
            border-color: var(--primary);
            box-shadow: 0 0 0 2px var(--primary), 0 0 10px var(--primary-glow);
            transform: scale(1.08);
            z-index: 2;
        }
        #drawColorPicker,
        #bgSolidPicker {
            appearance: none;
            -webkit-appearance: none;
            border: 2px solid var(--border-strong);
            width: 30px;
            height: 30px;
            min-width: 30px;
            min-height: 30px;
            border-radius: 8px;
            background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);
            cursor: pointer;
            padding: 0;
            overflow: hidden;
            flex-shrink: 0;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        }
        #drawColorPicker:hover,
        #bgSolidPicker:hover {
            transform: translateY(-1px) scale(1.05);
            border-color: #ffffff;
        }
        #drawColorPicker::-webkit-color-swatch-wrapper,
        #bgSolidPicker::-webkit-color-swatch-wrapper {
            padding: 3px;
        }
        #drawColorPicker::-webkit-color-swatch,
        #bgSolidPicker::-webkit-color-swatch {
            border: 1px solid rgba(255, 255, 255, 0.6);
            border-radius: 5px;
        }

        /* Tool Mode Selector Buttons Styling */
        .tool-mode-bar {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 6px;
            width: 100%;
        }
        .tool-mode-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            padding: 8px 10px;
            min-height: 40px;
            border-radius: var(--radius-md);
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            color: var(--text-secondary);
            font-family: var(--font-body);
            font-size: 12.5px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
        }
        .tool-mode-btn svg {
            width: 16px;
            height: 16px;
            flex-shrink: 0;
            transition: transform 0.18s ease;
        }
        .tool-mode-btn:hover {
            background: var(--surface-03);
            color: var(--text-primary);
            border-color: var(--border-strong);
        }
        .tool-mode-btn:active {
            transform: scale(0.97);
        }
        .tool-mode-btn.active {
            background: var(--primary);
            color: #ffffff;
            border-color: var(--primary-hover);
            box-shadow: 0 4px 12px var(--primary-glow);
        }
        .tool-mode-btn.active svg {
            color: #ffffff;
            transform: scale(1.1);
        }

        /* Layer Opacity Panel Styles */
        .opacity-panel {
            max-height: 280px;
        }
        .preset-opacity-row {
            display: flex;
            gap: 8px;
            width: 100%;
        }
        .btn-opacity-preset {
            flex: 1;
            padding: 10px 0;
            font-size: 13px;
            font-weight: 600;
            font-family: inherit;
            color: var(--text-secondary);
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: var(--radius-sm);
            cursor: pointer;
            transition: all 0.15s ease;
            min-height: 44px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .btn-opacity-preset:hover,
        .btn-opacity-preset:active {
            background: rgba(255, 255, 255, 0.12);
            color: var(--text-primary);
            border-color: var(--primary);
        }
        .btn-opacity-preset.active {
            background: var(--primary);
            color: #ffffff;
            border-color: var(--primary);
        }
        @keyframes aiSpin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }
        .ai-spin {
            animation: aiSpin 1s linear infinite;
        }
        .btn-restore-subtle {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            background: transparent;
            border: 1px solid transparent;
            color: var(--text-tertiary, #94a3b8);
            font-family: var(--font-body);
            font-size: 11.5px;
            font-weight: 500;
            padding: 6px 12px;
            margin-top: 8px;
            width: 100%;
            cursor: pointer;
            border-radius: var(--radius-sm);
            transition: all 0.15s ease;
            text-align: center;
        }
        .btn-restore-subtle:hover {
            color: #cbd5e1;
            background: rgba(255, 255, 255, 0.04);
            border-color: rgba(255, 255, 255, 0.08);
        }
        .btn-restore-subtle:active {
            color: #ffffff;
            background: rgba(255, 255, 255, 0.08);
        }
        .btn-restore-subtle.hidden {
            display: none !important;
        }
        .btn-restore-subtle svg {
            opacity: 0.7;
            flex-shrink: 0;
            transition: transform 0.2s ease;
        }
        .btn-restore-subtle:hover svg {
            opacity: 1;
            transform: rotate(-30deg);
        }

        /* Interactive Crop Modal (Pro Darkroom Experience) */
        .crop-modal {
            position: fixed;
            inset: 0;
            background: rgba(4, 5, 8, 0.94);
            backdrop-filter: blur(28px);
            -webkit-backdrop-filter: blur(28px);
            z-index: 250;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            padding: calc(var(--sat) + 8px) 16px calc(var(--sab) + 12px) 16px;
            opacity: 1;
            transition: opacity 0.25s ease;
        }
        .crop-modal.hidden {
            display: none;
            opacity: 0;
            pointer-events: none;
        }
        .crop-modal.closing {
            opacity: 0;
            pointer-events: none;
        }
        .crop-modal.closing .crop-container {
            transform: translateY(20px) scale(0.96);
            opacity: 0;
            transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .crop-container {
            width: 100%;
            max-width: 580px;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            gap: 12px;
        }
        .crop-header {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 10px;
            align-items: center;
            flex-shrink: 0;
        }
        .crop-header-bar {
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .crop-title {
            font-family: var(--font-display);
            font-size: 16px;
            font-weight: 700;
            color: var(--text-primary);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .crop-title svg {
            width: 18px;
            height: 18px;
            color: var(--primary);
        }
        .aspect-ratio-group {
            display: flex;
            align-items: center;
            gap: 6px;
            overflow-x: auto;
            max-width: 100%;
            padding: 4px 2px;
            scrollbar-width: none;
        }
        .aspect-ratio-group::-webkit-scrollbar {
            display: none;
        }
        .ratio-pill,
        .pill-btn {
            background: var(--surface-02);
            color: var(--text-secondary);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-pill);
            padding: 6px 14px;
            min-height: 36px;
            font-family: var(--font-mono);
            font-size: 11.5px;
            font-weight: 600;
            cursor: pointer;
            flex-shrink: 0;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
        }
        .ratio-pill:hover,
        .pill-btn:hover {
            background: var(--surface-03);
            color: var(--text-primary);
            border-color: var(--border-medium);
        }
        .ratio-pill.active,
        .pill-btn.active {
            background: var(--primary);
            color: #ffffff;
            border-color: var(--primary-hover);
            box-shadow: 0 0 14px var(--primary-glow);
        }
        .pill-group {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 8px;
            max-width: 100%;
            padding: 4px 0;
        }

        .crop-stage-wrapper {
            flex: 1;
            width: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            position: relative;
            min-height: 240px;
            overflow: hidden;
        }
        .crop-stage {
            position: relative;
            touch-action: none;
            user-select: none;
            -webkit-user-select: none;
            overflow: hidden;
            border-radius: 12px;
            box-shadow: 0 20px 48px rgba(0, 0, 0, 0.85);
            border: 1px solid var(--border-strong);
        }
        .crop-image {
            display: block;
            pointer-events: none;
            width: 100%;
            height: 100%;
            object-fit: contain;
            border-radius: 12px;
        }
        .crop-box {
            position: absolute;
            border: 2px solid var(--primary);
            box-shadow: 0 0 0 9999px rgba(4, 5, 8, 0.78);
            cursor: move;
            touch-action: none;
        }
        .crop-grid-h1, .crop-grid-h2, .crop-grid-v1, .crop-grid-v2 {
            position: absolute;
            pointer-events: none;
            background: rgba(255, 255, 255, 0.25);
        }
        .crop-grid-h1 { top: 33.333%; left: 0; right: 0; height: 1px; }
        .crop-grid-h2 { top: 66.666%; left: 0; right: 0; height: 1px; }
        .crop-grid-v1 { left: 33.333%; top: 0; bottom: 0; width: 1px; }
        .crop-grid-v2 { left: 66.666%; top: 0; bottom: 0; width: 1px; }

        .crop-handle {
            position: absolute;
            background: #ffffff;
            border: 2px solid var(--primary);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
            touch-action: none;
            z-index: 10;
        }
        .crop-handle::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            min-width: var(--touch-min);
            min-height: var(--touch-min);
            width: 100%;
            height: 100%;
        }
        .handle-nw { top: -6px; left: -6px; width: 14px; height: 14px; border-radius: 3px 0 0 0; cursor: nwse-resize; }
        .handle-ne { top: -6px; right: -6px; width: 14px; height: 14px; border-radius: 0 3px 0 0; cursor: nesw-resize; }
        .handle-sw { bottom: -6px; left: -6px; width: 14px; height: 14px; border-radius: 0 0 0 3px; cursor: nesw-resize; }
        .handle-se { bottom: -6px; right: -6px; width: 14px; height: 14px; border-radius: 0 0 3px 0; cursor: nwse-resize; }

        .handle-n { top: -4px; left: 50%; transform: translateX(-50%); width: 22px; height: 8px; border-radius: 4px; cursor: ns-resize; }
        .handle-s { bottom: -4px; left: 50%; transform: translateX(-50%); width: 22px; height: 8px; border-radius: 4px; cursor: ns-resize; }
        .handle-w { left: -4px; top: 50%; transform: translateY(-50%); width: 8px; height: 22px; border-radius: 4px; cursor: ew-resize; }
        .handle-e { right: -4px; top: 50%; transform: translateY(-50%); width: 8px; height: 22px; border-radius: 4px; cursor: ew-resize; }

        .crop-dimensions {
            font-family: var(--font-mono);
            font-size: 12px;
            color: var(--primary-hover);
            text-align: center;
        }

        .crop-footer {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            flex-shrink: 0;
        }
        .btn-crop-action {
            border-radius: var(--radius-md);
            font-family: var(--font-body);
            font-size: 13.5px;
            font-weight: 600;
            padding: 10px 18px;
            min-height: var(--touch-min);
            cursor: pointer;
            border: none;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
        }
        .btn-crop-action svg {
            width: 16px;
            height: 16px;
        }
        .btn-crop-reset {
            background: transparent;
            color: var(--text-secondary);
            border: 1px solid var(--border-subtle);
        }
        .btn-crop-cancel {
            background: var(--surface-02);
            color: var(--text-primary);
            border: 1px solid var(--border-subtle);
        }
        .btn-crop-apply {
            background: var(--accent-emerald);
            color: #031c13;
            font-weight: 700;
            box-shadow: 0 4px 16px rgba(16, 185, 129, 0.3);
        }

        /* Keyboard Shortcuts Modal */
        .shortcuts-modal {
            position: fixed;
            inset: 0;
            background: rgba(4, 5, 8, 0.85);
            backdrop-filter: blur(20px);
            z-index: 300;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 16px;
        }
        .shortcuts-modal.hidden {
            display: none;
        }
        .shortcuts-card {
            width: 100%;
            max-width: 440px;
            background: var(--surface-01);
            border: 1px solid var(--border-strong);
            border-radius: var(--radius-xl);
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 16px;
            box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
        }
        .shortcuts-list {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .shortcut-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 13px;
        }
        .kbd-key {
            font-family: var(--font-mono);
            background: var(--surface-03);
            color: var(--primary-hover);
            border: 1px solid var(--border-strong);
            padding: 4px 8px;
            border-radius: 6px;
            font-size: 11px;
            font-weight: 600;
        }

        /* Privacy Policy Modal */
        .privacy-modal {
            position: fixed;
            inset: 0;
            background: rgba(4, 5, 8, 0.88);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            z-index: 350;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 16px;
            opacity: 1;
            transition: opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .privacy-modal.hidden {
            display: none;
            opacity: 0;
            pointer-events: none;
        }
        .privacy-modal.closing {
            opacity: 0;
            pointer-events: none;
        }
        .privacy-modal.closing .privacy-card {
            transform: translateY(20px) scale(0.96);
            opacity: 0;
            transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .privacy-card {
            width: 100%;
            max-width: 520px;
            max-height: 88vh;
            overflow-y: auto;
            background: var(--surface-01);
            border: 1px solid var(--border-strong);
            border-radius: var(--radius-xl);
            padding: 22px;
            display: flex;
            flex-direction: column;
            gap: 16px;
            box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85);
        }
        .privacy-hero {
            display: flex;
            flex-direction: column;
            gap: 6px;
            padding: 14px 16px;
            background: rgba(16, 185, 129, 0.07);
            border: 1px solid rgba(16, 185, 129, 0.24);
            border-radius: var(--radius-md);
        }
        .privacy-hero-badge {
            font-family: var(--font-mono);
            font-size: 10px;
            font-weight: 700;
            color: #10b981;
            letter-spacing: 0.06em;
        }
        .privacy-hero-title {
            font-family: var(--font-display);
            font-size: 15px;
            font-weight: 700;
            color: var(--text-primary);
        }
        .privacy-hero-desc {
            font-size: 12.5px;
            line-height: 1.5;
            color: var(--text-secondary);
        }
        .privacy-grid {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .privacy-item {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            padding: 12px;
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
        }
        .privacy-item-icon {
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(59, 130, 246, 0.1);
            border-radius: 8px;
            color: var(--primary);
            flex-shrink: 0;
        }
        .privacy-item-icon svg {
            width: 16px;
            height: 16px;
        }
        .privacy-item-content {
            display: flex;
            flex-direction: column;
            gap: 3px;
        }
        .privacy-item-title {
            font-size: 12.5px;
            font-weight: 600;
            color: var(--text-primary);
        }
        .privacy-item-text {
            font-size: 11.5px;
            line-height: 1.45;
            color: var(--text-secondary);
        }
        .privacy-demo-box {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            padding: 12px 14px;
            background: var(--surface-02);
            border: 1px solid var(--border-strong);
            border-radius: var(--radius-md);
            margin-top: 2px;
        }
        .privacy-demo-copy {
            display: flex;
            flex-direction: column;
            gap: 2px;
        }
        .privacy-demo-title {
            font-size: 12px;
            font-weight: 600;
            color: var(--text-primary);
        }
        .privacy-demo-sub {
            font-size: 11px;
            color: var(--text-muted);
        }
        @media (max-width: 440px) {
            .privacy-card {
                padding: 16px 14px;
            }
            .privacy-demo-box {
                flex-direction: column;
                align-items: stretch;
            }
        }

        /* Native iOS Action Sheet: Load Photo */
        .action-sheet-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.65);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            z-index: 250;
            display: flex;
            align-items: flex-end;
            justify-content: center;
            opacity: 1;
            transition: opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .action-sheet-overlay.hidden {
            display: none;
            opacity: 0;
            pointer-events: none;
        }
        .action-sheet-overlay.closing {
            opacity: 0;
            pointer-events: none;
        }
        .action-sheet-overlay.closing .action-sheet-panel {
            transform: translateY(100%);
            transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .action-sheet-panel {
            width: 100%;
            max-width: 500px;
            background: var(--surface-01);
            border-top-left-radius: 24px;
            border-top-right-radius: 24px;
            border: 1px solid var(--border-subtle);
            border-bottom: none;
            box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.85);
            padding: 12px 16px calc(var(--sab) + 16px) 16px;
            display: flex;
            flex-direction: column;
            gap: 12px;
            transform: translateY(0);
            transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
            will-change: transform;
            touch-action: pan-y;
            animation: sheetSlideUp 0.22s cubic-bezier(0.32, 0.72, 0, 1);
        }
        .action-sheet-panel.swiping {
            transition: none !important;
        }
        @keyframes sheetSlideUp {
            from { transform: translateY(100%); }
            to { transform: translateY(0); }
        }
        .action-sheet-grabber {
            width: 36px;
            height: 4px;
            border-radius: 2px;
            background: rgba(255, 255, 255, 0.28);
            margin: 0 auto 6px auto;
            cursor: grab;
            touch-action: none;
        }
        .action-sheet-header {
            text-align: center;
            padding: 0 8px 4px 8px;
        }
        .action-sheet-title {
            font-family: var(--font-display);
            font-size: 16px;
            font-weight: 700;
            color: var(--text-primary);
        }
        .action-sheet-subtitle {
            font-family: var(--font-body);
            font-size: 12px;
            color: var(--text-muted);
            margin-top: 2px;
        }
        .action-sheet-options {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }
        .action-sheet-item {
            display: flex;
            align-items: center;
            gap: 14px;
            padding: 14px 16px;
            min-height: 58px;
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-lg);
            color: var(--text-primary);
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            touch-action: manipulation;
            user-select: none;
            text-decoration: none;
            width: 100%;
            text-align: left;
            box-sizing: border-box;
        }
        .action-sheet-item:hover {
            background: var(--surface-03);
            border-color: var(--primary);
            transform: translateY(-1px);
        }
        .action-sheet-item:active {
            transform: scale(0.98);
            background: var(--primary-subtle);
        }
        .action-sheet-item:disabled,
        .action-sheet-item[aria-disabled="true"],
        .action-sheet-item.disabled {
            opacity: 0.45;
            cursor: not-allowed;
            pointer-events: none;
            transform: none !important;
            border-color: var(--border-subtle) !important;
            background: var(--surface-02) !important;
        }
        .sheet-item-icon {
            width: 38px;
            height: 38px;
            border-radius: 10px;
            background: var(--surface-03);
            border: 1px solid var(--border-strong);
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            color: var(--primary);
        }
        .sheet-item-icon svg {
            width: 20px;
            height: 20px;
        }
        .sheet-item-text {
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 2px;
        }
        .sheet-item-title {
            font-family: var(--font-body);
            font-size: 14px;
            font-weight: 600;
            color: var(--text-primary);
        }
        .sheet-item-desc {
            font-size: 11.5px;
            color: var(--text-secondary);
        }
        .sheet-item-badge {
            font-family: var(--font-mono);
            font-size: 11px;
            color: var(--text-muted);
            background: rgba(255, 255, 255, 0.06);
            border: 1px solid rgba(255, 255, 255, 0.1);
            padding: 3px 7px;
            border-radius: 6px;
        }
        .action-sheet-cancel {
            width: 100%;
            min-height: 46px;
            border-radius: var(--radius-md);
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid var(--border-subtle);
            color: var(--text-secondary);
            font-family: var(--font-body);
            font-size: 13.5px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
            margin-top: 4px;
        }
        .action-sheet-cancel:active {
            background: rgba(255, 255, 255, 0.1);
            color: var(--text-primary);
        }

        /* Sticker Picker Modal */
        .sticker-picker-card {
            max-width: 440px;
        }
        .sticker-capture-container {
            margin: 14px 0 10px 0;
        }
        .sticker-capture-zone {
            min-height: 90px;
            max-height: 140px;
            overflow-y: auto;
            border: 2px dashed var(--primary);
            background: var(--surface-02);
            border-radius: var(--radius-lg);
            padding: 16px;
            font-size: 13.5px;
            line-height: 1.5;
            color: var(--text-primary);
            display: flex;
            align-items: center;
            justify-content: center;
            text-align: center;
            outline: none;
            cursor: pointer;
            transition: all 0.2s ease;
            box-sizing: border-box;
            user-select: text;
            -webkit-user-select: text;
        }
        .sticker-capture-zone:focus {
            border-style: solid;
            background: var(--surface-03);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
        }
        .sticker-capture-zone:empty:before {
            content: attr(data-placeholder);
            color: var(--text-muted);
            pointer-events: none;
            display: block;
        }
        .sticker-actions-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 10px;
        }
        .btn-sticker-action {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-height: var(--touch-min);
            min-width: var(--touch-min);
            background: var(--surface-02);
            border: 1px solid var(--border-subtle);
            border-radius: var(--radius-md);
            color: var(--text-primary);
            font-family: var(--font-body);
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            text-decoration: none;
            box-sizing: border-box;
            transition: all 0.2s ease;
            touch-action: manipulation;
        }
        .btn-sticker-action:hover {
            background: var(--surface-03);
            border-color: var(--border-strong);
        }
        .btn-sticker-action:active {
            transform: scale(0.98);
            background: var(--primary-subtle);
        }
        .btn-sticker-action svg {
            width: 16px;
            height: 16px;
            color: var(--primary);
        }

        /* Visually hidden accessible file input (compatible with iOS Safari / WebKit) */
        #imageLoader {
            position: fixed;
            top: -10000px;
            left: -10000px;
            width: 1px;
            height: 1px;
            padding: 0;
            margin: -1px;
            overflow: hidden;
            clip: rect(0, 0, 0, 0);
            white-space: nowrap;
            border: 0;
            opacity: 0;
            pointer-events: none;
        }

        /* Small Mobile Screen Ergonomics (< 440px viewport e.g. iPhone SE/Mini/16) */
        @media (max-width: 440px) {
            .app-title {
                font-size: 14.5px;
            }
            .version-tag {
                font-size: 8.5px;
                padding: 1px 4px;
            }
            #shortcutsBtn {
                display: none;
            }
            .hud-badge {
                padding: 4px 7px;
                font-size: 9.5px;
                white-space: nowrap;
                letter-spacing: 0;
            }
            .header-actions {
                gap: 3.5px;
            }
            .btn-icon-hud {
                width: 35px;
                height: 35px;
            }
        }

        /* Light Checkerboard Background for Stage Previews */
        .light-checkerboard {
            background-color: #f1f5f9;
            background-image:
                linear-gradient(45deg, #cbd5e1 25%, transparent 25%),
                linear-gradient(-45deg, #cbd5e1 25%, transparent 25%),
                linear-gradient(45deg, transparent 75%, #cbd5e1 75%),
                linear-gradient(-45deg, transparent 75%, #cbd5e1 75%);
            background-size: 16px 16px;
            background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
        }

        /* Desktop Container Framing */
        @media (min-width: 640px) {
            body {
                background: #040508;
            }
            .app-container {
                width: 100%;
                max-width: 640px;
                height: 100%;
                display: flex;
                flex-direction: column;
                border-left: 1px solid var(--border-subtle);
                border-right: 1px solid var(--border-subtle);
            }
        }