* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0b;
    --bg-secondary: #111113;
    --bg-tertiary: #1a1a1d;
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --border: #27272a;
    --border-hover: #3f3f46;
    --danger: #ef4444;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: contain;
}

body {
    font-family: 'Manrope', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #818cf8, #c084fc, #f472b6);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-icon svg {
    width: 16px;
    height: 16px;
    color: white;
}

.logo-text {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.section-title {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

/* Drop overlay for main area */
.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(129, 140, 248, 0.15);
    border: 3px dashed var(--accent);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 100;
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
}
.drop-overlay.active { display: flex; }
.drop-overlay svg {
    width: 48px;
    height: 48px;
    opacity: 0.8;
}

/* History strip */
.history-strip {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 2px;
}
.history-strip::-webkit-scrollbar {
    height: 4px;
}
.history-strip::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}
.history-item {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    flex-shrink: 0;
    object-fit: cover;
    transition: all 0.15s ease;
    position: relative;
}
.history-item:hover { border-color: var(--border-hover); }
.history-item.active { border-color: var(--accent); }
.history-item-wrapper {
    position: relative;
    flex-shrink: 0;
}
.history-item-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    color: white;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.history-item-wrapper:hover .history-item-remove { display: flex; }

/* Form Controls */
label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 6px 8px;
    font-size: 11px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    transition: all 0.2s ease;
    width: 100%;
}

input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: none;
    height: 40px;
    font-size: 10px;
    line-height: 1.4;
    overflow: hidden;
}

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

.row > * {
    flex: 1;
}

.row span {
    flex: 0;
    color: var(--text-muted);
    font-size: 11px;
}

/* Buttons */
.btn {
    padding: 6px 10px;
    border-radius: 5px;
    font-size: 10px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.btn svg {
    width: 12px;
    height: 12px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Gradient Preview */
.gradient-row {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.gradient-preview {
    flex: 1;
    height: 32px;
    border-radius: 5px;
    position: relative;
}

.gradient-preview::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 5px;
    pointer-events: none;
}

/* Slider с tooltip */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.slider-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

.slider-track-container {
    position: relative;
}

/* Tooltip */
.slider-tooltip {
    position: absolute;
    bottom: 100%;
    left: 0;
    transform: translateX(-50%);
    margin-bottom: 8px;
    background: var(--accent);
    color: #fff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    white-space: nowrap;
    z-index: 100;
}

.slider-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--accent);
}

.slider-tooltip.visible {
    opacity: 1;
}

/* Slider track */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    cursor: pointer;
}

/* Slider thumb */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover,
input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.2);
}

/* Firefox */
input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

/* Main Area */
.main {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}


.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
    position: relative;
}

.preview-container {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-wrapper {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    max-width: 100%;
    max-height: 100%;
    position: relative;
}

#canvas {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 100px);
    height: auto;
    object-fit: contain;
}

#overlayCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.canvas-wrapper.blur-mode #overlayCanvas {
    pointer-events: auto;
    cursor: crosshair;
}

/* Empty State */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
    z-index: 10;
    pointer-events: auto;
    background: rgba(10, 10, 11, 0.85);
    padding: 32px 48px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
}

.empty-state svg {
    width: 40px;
    height: 40px;
    margin-bottom: 10px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 11px;
}

.empty-state #selectFileBtn {
    color: var(--accent);
    cursor: pointer;
}
.empty-state #selectFileBtn:hover {
    text-decoration: underline;
}

/* Footer */
.footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-secondary);
}

.footer-info {
    flex: 1;
    font-size: 10px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.footer-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.download-btn {
    padding: 8px 16px;
    font-size: 11px;
}

/* Presets */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.preset-btn {
    aspect-ratio: 1;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.preset-btn:hover {
    transform: scale(1.1);
    z-index: 1;
}

.preset-btn.active {
    border-color: white;
}

/* Code row */
.code-row {
    display: flex;
    gap: 4px;
}

.code-row textarea {
    flex: 1;
}

.code-row .btn {
    padding: 6px 8px;
    flex-shrink: 0;
}

/* Blur zones list */
.blur-zones-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 80px;
    overflow-y: auto;
}

.blur-zone-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-secondary);
}

.blur-zone-item button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
}

.blur-zone-item button:hover {
    color: var(--danger);
}

.blur-zone-item button svg {
    width: 12px;
    height: 12px;
}

.blur-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 6px;
}

.blur-type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
}
.blur-type-btn {
    padding: 6px 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.blur-type-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.blur-type-btn span { font-size: 8px; text-transform: uppercase; }

.blur-options { display: none; margin-top: 6px; }
.blur-options.visible { display: flex; }
.direction-toggle { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.direction-btn { padding: 8px; display: flex; align-items: center; justify-content: center; }
.direction-btn svg { width: 16px; height: 16px; }

.frame-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
}

.frame-btn {
    aspect-ratio: 1;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 40px;
}

.frame-btn svg { width: 16px; height: 16px; }
.frame-btn span { font-size: 8px; text-transform: uppercase; }

.frame-options { display: none; flex-direction: column; gap: 6px; margin-top: 6px; }
.frame-options.visible { display: flex; }
.color-options { display: flex; gap: 4px; }
.color-btn { flex: 1; padding: 6px 8px; font-size: 10px; }
#windowTitle { display: none; margin-top: 4px; }
#windowTitle.visible { display: block; }

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    margin-top: 4px;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 32px;
    height: 18px;
    background: var(--bg-tertiary);
    border-radius: 9px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::after {
    left: 16px;
    background: white;
}

.toggle-switch:hover .toggle-slider {
    border-color: var(--border-hover);
}

.toggle-switch input:checked + .toggle-slider:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.toggle-label {
    user-select: none;
}

/* Compact mode for screens < 800px height */
@media (max-height: 800px) {
    .sidebar {
        padding: 8px;
        gap: 6px;
    }

    .section { gap: 3px; }

    textarea { height: 36px; }

    .frame-btn {
        min-height: 36px;
    }

    .blur-zones-list { max-height: 60px; }
}

/* Ultra-compact mode for screens < 650px height */
@media (max-height: 650px) {
    .sidebar {
        padding: 6px;
        gap: 4px;
    }

    .section-title { font-size: 8px; }

    .gradient-preview { height: 24px; }

    .slider-group { gap: 2px; }

    .frame-btn {
        min-height: 32px;
    }
}

/* Mobile: Sidebar handle (hidden on desktop) */
.sidebar-handle {
    display: none;
    justify-content: center;
    padding: 12px 0 8px;
    cursor: pointer;
}

.sidebar-handle .handle-bar {
    width: 40px;
    height: 4px;
    background: var(--border-hover);
    border-radius: 2px;
    transition: background 0.2s ease;
}

/* Mobile: Peek controls (hidden on desktop) */
.sidebar-peek {
    display: none;
}

/* Mobile: Sidebar content wrapper */
.sidebar-content {
    display: contents;
}

/* Hide gradient code section on mobile */
@media (max-width: 768px) {
    .section:has(#gradientCode) {
        display: none;
    }
}

/* Main mobile breakpoint */
@media (max-width: 768px) {
    .app {
        display: block;
        height: 100dvh;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 75dvh;
        border-right: none;
        border-top: none;
        border-radius: 20px 20px 0 0;
        transform: translateY(calc(100% - 64px));
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        padding-bottom: env(safe-area-inset-bottom, 0);
        box-shadow:
            0 -4px 16px rgba(0, 0, 0, 0.5),
            0 -1px 0 rgba(255, 255, 255, 0.06);
    }

    /* Gradient line at top */
    .sidebar::before {
        content: '';
        position: absolute;
        top: 0;
        left: 20px;
        right: 20px;
        height: 1px;
        background: linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.15) 30%,
            rgba(255, 255, 255, 0.15) 70%,
            transparent
        );
        pointer-events: none;
        z-index: 1;
    }

    .sidebar.expanded {
        transform: translateY(0);
    }

    .sidebar-handle {
        display: flex;
    }

    /* Enhanced handle bar for mobile */
    .sidebar-handle .handle-bar {
        width: 36px;
        height: 5px;
        background: rgba(255, 255, 255, 0.3);
    }

    .sidebar-handle:active .handle-bar {
        background: rgba(129, 140, 248, 0.6);
    }

    /* Attention-grabbing bounce for collapsed sidebar */
    .sidebar:not(.expanded) {
        animation: sidebar-hint 4s ease-in-out 2s infinite;
    }

    @keyframes sidebar-hint {
        0%, 80%, 100% {
            transform: translateY(calc(100% - 64px));
            box-shadow:
                0 -4px 16px rgba(0, 0, 0, 0.5),
                0 -1px 0 rgba(255, 255, 255, 0.06);
        }
        86% {
            transform: translateY(calc(100% - 80px));
            box-shadow:
                0 -8px 30px rgba(129, 140, 248, 0.3),
                0 -4px 16px rgba(0, 0, 0, 0.5),
                0 -1px 0 rgba(255, 255, 255, 0.1);
        }
        92% {
            transform: translateY(calc(100% - 64px));
            box-shadow:
                0 -4px 16px rgba(0, 0, 0, 0.5),
                0 -1px 0 rgba(255, 255, 255, 0.06);
        }
        96% {
            transform: translateY(calc(100% - 72px));
            box-shadow:
                0 -6px 20px rgba(129, 140, 248, 0.2),
                0 -4px 16px rgba(0, 0, 0, 0.5),
                0 -1px 0 rgba(255, 255, 255, 0.08);
        }
    }

    .sidebar-peek {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px 12px;
        gap: 12px;
    }

    .sidebar.expanded .sidebar-peek {
        display: none;
    }

    .sidebar:not(.expanded) .logo,
    .sidebar:not(.expanded) .sidebar-content {
        display: none;
    }

    .sidebar-content {
        display: flex;
        flex-direction: column;
        gap: 8px;
        overflow-y: auto;
        flex: 1;
        min-height: 0;
    }

    .sidebar-handle,
    .sidebar-peek {
        flex-shrink: 0;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    .empty-state {
        cursor: pointer;
    }

    .empty-state .ctrl-hint {
        display: none;
    }

    .main {
        height: 100dvh;
        padding-bottom: 64px;
    }

    #canvas {
        max-height: calc(100dvh - 180px);
    }

    /* Touch targets */
    .btn {
        min-height: 44px;
        padding: 10px 14px;
    }

    input[type="text"],
    input[type="number"],
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .presets-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .footer {
        flex-direction: column;
        gap: 12px;
    }

    .footer-actions {
        flex-direction: column;
        width: 100%;
    }

    .download-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Medium mobile */
@media (min-width: 481px) and (max-width: 768px) {
    .presets-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}
