@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-main: #09090b;
    --bg-surface: #18181b;
    --bg-surface-hover: #27272a;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --text-primary: #f8fafc;
    --text-sec: #a1a1aa;
    --border: #27272a;
    --glass-bg: rgba(24, 24, 27, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    touch-action: manipulation;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #3f3f46;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #52525b;
}

/* Utilities */
.btn {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn:hover {
    background: var(--bg-surface-hover);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-icon {
    padding: 8px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-sec);
}

.btn-icon:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.btn-icon.active {
    color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

/* Layout Header */
.header {
    height: 64px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 100;
}

.brand {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand span {
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Main Workspace layout */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar Tooling */
.sidebar {
    width: 80px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    gap: 16px;
    z-index: 50;
    overflow-y: auto;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 60px;
    padding: 10px 0;
    border-radius: 12px;
    color: var(--text-sec);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn span {
    font-size: 11px;
    font-weight: 500;
}

.tool-btn:hover {
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

.tool-btn.active {
    color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

/* Settings Panel */
.panel {
    width: 320px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
}

.panel.open {
    transform: translateX(0);
}

.panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.panel-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    background: #000;
    background-image: linear-gradient(45deg, #111 25%, transparent 25%, transparent 75%, #111 75%, #111), linear-gradient(45deg, #111 25%, transparent 25%, transparent 75%, #111 75%, #111);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    padding: 24px;
}

.canvas-wrapper {
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#mainCanvas {
    max-width: 100%;
    max-height: 80vh;
    z-index: 1;
    display: block;
}

#drawCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

#drawCanvas.active {
    pointer-events: all;
    cursor: crosshair;
}

.placeholder {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-sec);
}

#uploadBtn {
    display: none;
}

/* Ad Container */
.ad-slot {
    width: 100%;
    min-height: 90px;
    background: var(--bg-surface);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-sec);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-top: 1px solid var(--border);
    z-index: 40;
}

/* UI Controls in Panel */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-group label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.control-group label span {
    color: var(--text-sec);
}

input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Grid Lists */
.filter-grid,
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.filter-item {
    background: var(--bg-main);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
}

.filter-item:hover {
    border-color: var(--border);
}

.filter-item.active {
    border-color: var(--accent);
}

.filter-thumb {
    width: 100%;
    height: 70px;
    background-size: cover;
    background-position: center;
}

.filter-name {
    font-size: 12px;
    padding: 8px;
    text-align: center;
}

/* Colors */
.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
}

.color-swatch.active {
    transform: scale(1.1);
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--bg-main);
}

.color-swatch[data-c="#ffffff"] {
    border: 1px solid var(--border);
}

/* Crop ratios */
.ratio-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.ratio-btn {
    background: var(--bg-main);
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: 6px;
    color: var(--text-sec);
    cursor: pointer;
    font-size: 12px;
    text-align: center;
}

.ratio-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Responsive */
@media (max-width: 768px) {
    .workspace {
        flex-direction: column-reverse;
    }

    .sidebar {
        width: 100%;
        height: 70px;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        overflow-x: auto;
        padding: 0 16px;
        justify-content: flex-start;
    }

    .tool-btn {
        min-width: 60px;
    }

    .panel {
        width: 100%;
        top: auto;
        height: 45vh;
        transform: translateY(100%);
        border-left: none;
        border-top: 1px solid var(--border);
        z-index: 200;
    }

    .panel.open {
        transform: translateY(0);
    }

    .ad-slot {
        display: none;
        /* simple responsive handling for bottom */
    }
}

select.format-select {
    background: var(--bg-surface);
    color: white;
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 6px;
    outline: none;
}