/* ============================================
   PixelMix Editor — Redesigned UX
   Mobile-first, CapCut/Instagram-inspired
   ============================================ */

/* ----- Design Tokens ----- */
:root {
    --bg-dark:        #0a0a0f;
    --bg-card:        #111119;
    --bg-surface:     #1a1a28;
    --bg-hover:       #22223a;
    --accent:         #c084fc;
    --accent-2:       #a855f7;
    --accent-soft:    rgba(192, 132, 252, 0.12);
    --text-primary:   #f0f0f5;
    --text-secondary: #9494a8;
    --border:         rgba(148, 148, 168, 0.12);
    --border-mid:     rgba(148, 148, 168, 0.22);
    --coral:          #fb7185;
    --teal:           #2dd4bf;
    --amber:          #fbbf24;
    --danger:         #ef4444;
    --nav-h:          52px;
    --toolbar-w:      80px;
    --panel-w:        280px;
    --mobile-bar-h:   62px;
}

/* ----- Reset & Base ----- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
svg { display: block; flex-shrink: 0; }

/* ----- Scrollbar ----- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148,148,168,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148,148,168,0.35); }

/* ============================================
   TOP NAVIGATION
   ============================================ */
.editor-nav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    gap: 0.5rem;
}

.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--coral));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
    user-select: none;
    white-space: nowrap;
}

.nav-center {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    justify-content: center;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.nav-icon-btn svg {
    width: 16px; height: 16px;
}

.nav-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-mid);
}

.nav-sep {
    width: 1px;
    height: 22px;
    background: var(--border);
    margin: 0 0.15rem;
}

/* Export Button */
.export-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    padding: 0.45rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    transition: filter 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
}

.export-btn svg { width: 14px; height: 14px; }

.export-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.export-btn:active { transform: translateY(0); filter: brightness(0.95); }

.export-btn.full-width {
    width: 100%;
    justify-content: center;
    padding: 0.75rem;
    margin-top: 1rem;
    font-size: 0.95rem;
    border-radius: 10px;
}

/* ============================================
   MAIN EDITOR BODY LAYOUT
   ============================================ */
.editor-body {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow: hidden;
}

/* ============================================
   LEFT TOOLBAR (Desktop) — CapCut-style
   ============================================ */
.editor-toolbar {
    width: var(--toolbar-w);
    background: #0d0d12;
    border-right: 1px solid rgba(255, 255, 255, 0.055);
    padding: 10px 0 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    scrollbar-width: none;
}

.editor-toolbar::-webkit-scrollbar { display: none; }

/* Tool-specific accent colors */
.tool-btn[data-tool="select"]  { --t-accent: #2dd4bf; --t-bg: rgba(45,212,191,0.14); }
.tool-btn[data-tool="crop"]    { --t-accent: #fbbf24; --t-bg: rgba(251,191,36,0.14); }
.tool-btn[data-tool="text"]    { --t-accent: #60a5fa; --t-bg: rgba(96,165,250,0.14); }
.tool-btn[data-tool="draw"]    { --t-accent: #f472b6; --t-bg: rgba(244,114,182,0.14); }
.tool-btn[data-tool="rect"],
.tool-btn[data-tool="circle"],
.tool-btn[data-tool="line"]    { --t-accent: #a78bfa; --t-bg: rgba(167,139,250,0.14); }
#rotate-left-btn, #flip-h-btn  { --t-accent: #94a3b8; --t-bg: rgba(148,163,184,0.12); }
#delete-btn                     { --t-accent: #fb7185; --t-bg: rgba(251,113,133,0.14); }

.tool-btn {
    width: 68px;
    height: 62px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    color: var(--text-secondary);
    border: none;
    background: transparent;
    transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
    padding: 0;
    position: relative;
}

/* Icon badge container */
.tool-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(148, 148, 168, 0.09);
    border: 1px solid rgba(148, 148, 168, 0.08);
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
    color: inherit;
}

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

.tool-btn > span:last-child {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-secondary);
    transition: color 0.18s ease;
    line-height: 1;
}

/* Hover state */
.tool-btn:hover {
    color: var(--t-accent, var(--accent));
}
.tool-btn:hover .tool-icon {
    background: var(--t-bg, var(--accent-soft));
    border-color: rgba(255,255,255,0.1);
    transform: scale(1.06);
}
.tool-btn:hover > span:last-child {
    color: var(--t-accent, var(--accent));
}

/* Active state */
.tool-btn.active {
    color: var(--t-accent, var(--accent));
}
.tool-btn.active .tool-icon {
    background: var(--t-bg, var(--accent-soft));
    border-color: color-mix(in srgb, var(--t-accent, var(--accent)) 40%, transparent);
    box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--t-accent, var(--accent)) 35%, transparent),
                0 4px 12px color-mix(in srgb, var(--t-accent, var(--accent)) 25%, transparent);
}
.tool-btn.active > span:last-child {
    color: var(--t-accent, var(--accent));
}

/* Click micro-animation */
.tool-btn:active { transform: scale(0.94); }
.tool-btn:active .tool-icon { transform: scale(0.96); }

/* Danger (delete) overrides */
.tool-btn.danger:hover {
    color: var(--coral);
}
.tool-btn.danger:hover .tool-icon {
    background: rgba(251, 113, 133, 0.15);
    border-color: rgba(251, 113, 133, 0.2);
}

.toolbar-sep {
    width: 36px;
    height: 1px;
    background: rgba(148, 148, 168, 0.1);
    margin: 6px 0;
    flex-shrink: 0;
    border-radius: 1px;
}

/* ============================================
   CANVAS AREA
   ============================================ */
.editor-canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   UPLOAD OVERLAY — Redesigned
   ============================================ */
.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: var(--bg-dark);
    padding: 1rem;
}

.upload-overlay.hidden { display: none !important; }

.upload-drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem 2rem;
    border: 2px dashed var(--border-mid);
    border-radius: 20px;
    max-width: 400px;
    width: 100%;
    transition: all 0.2s ease;
    background: var(--bg-card);
}

.upload-drop-zone.drag-active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.upload-icon {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.upload-icon svg { width: 36px; height: 36px; }

.upload-drop-zone h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.upload-drop-zone > p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.upload-browse-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.75rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.upload-browse-btn svg { width: 16px; height: 16px; }

.upload-browse-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }

.upload-browse-btn input[type="file"] { display: none; }

.upload-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Upload loading state */
.upload-spinner {
    width: 48px; height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   CANVAS WRAPPER
   ============================================ */
.canvas-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    height: 100%;
    background: repeating-conic-gradient(rgba(148,148,168,0.04) 0% 25%, transparent 0% 50%) 0 0 / 20px 20px;
}

.canvas-wrapper.hidden { display: none !important; }

.canvas-wrapper .canvas-container {
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
}

/* ============================================
   CROP OVERLAY
   ============================================ */
.crop-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.crop-overlay.hidden { display: none !important; }

.crop-overlay.active { pointer-events: all; }

/* Darkened shade outside crop box */
.crop-shade {
    position: absolute;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1;
}

.crop-shade-top    { top: 0; left: 0; right: 0; }
.crop-shade-bottom { bottom: 0; left: 0; right: 0; }
.crop-shade-left   { top: 0; bottom: 0; left: 0; }
.crop-shade-right  { top: 0; bottom: 0; right: 0; }

/* The crop box itself */
.crop-box {
    position: absolute;
    border: 2px solid #fff;
    z-index: 2;
    cursor: move;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
}

/* Rule of thirds grid */
.crop-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.crop-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.2);
}

.crop-line.h1 { top: 33.33%; left: 0; right: 0; height: 1px; }
.crop-line.h2 { top: 66.66%; left: 0; right: 0; height: 1px; }
.crop-line.v1 { left: 33.33%; top: 0; bottom: 0; width: 1px; }
.crop-line.v2 { left: 66.66%; top: 0; bottom: 0; width: 1px; }

/* Crop handles */
.crop-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 3px;
    z-index: 3;
    cursor: nwse-resize;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.crop-handle.tl { top: -4px;  left: -4px;  cursor: nwse-resize; border-radius: 3px 0 0 0; }
.crop-handle.tr { top: -4px;  right: -4px; cursor: nesw-resize; border-radius: 0 3px 0 0; }
.crop-handle.bl { bottom: -4px; left: -4px;  cursor: nesw-resize; border-radius: 0 0 0 3px; }
.crop-handle.br { bottom: -4px; right: -4px; cursor: nwse-resize; border-radius: 0 0 3px 0; }
.crop-handle.tc { top: -4px;  left: 50%; transform: translateX(-50%); cursor: ns-resize; border-radius: 3px; }
.crop-handle.bc { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: ns-resize; border-radius: 3px; }
.crop-handle.ml { top: 50%;  left: -4px;  transform: translateY(-50%); cursor: ew-resize; border-radius: 3px; }
.crop-handle.mr { top: 50%;  right: -4px; transform: translateY(-50%); cursor: ew-resize; border-radius: 3px; }

/* Crop action bar */
.crop-actions-bar {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(10, 10, 15, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-mid);
    border-radius: 14px;
    padding: 0.6rem 1rem;
    white-space: nowrap;
}

.crop-actions-bar.hidden { display: none !important; }

.crop-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.crop-action-btn {
    padding: 0.5rem 1.1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    transition: all 0.15s ease;
}

.crop-action-btn.cancel {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.crop-action-btn.cancel:hover { color: var(--text-primary); border-color: var(--border-mid); }

.crop-action-btn.apply {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
}

.crop-action-btn.apply:hover { filter: brightness(1.1); }

/* ============================================
   VIDEO CONTAINER
   ============================================ */
.video-container {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #000;
}

.video-container.hidden { display: none !important; }

#video-player {
    flex: 1;
    width: 100%;
    object-fit: contain;
    background: #000;
    min-height: 0;
}

.video-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.video-play-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.video-play-btn:hover { background: var(--bg-hover); }

.video-play-btn svg { width: 14px; height: 14px; }

#video-timeline {
    flex: 1;
    accent-color: var(--accent);
}

.video-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 40px;
    font-variant-numeric: tabular-nums;
}

.video-trim-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.trim-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.trim-controls { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }

.trim-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.trim-row span:first-child { min-width: 22px; }

.trim-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

/* ============================================
   RIGHT PROPERTIES PANEL (Desktop)
   ============================================ */
.editor-properties {
    width: var(--panel-w);
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    padding: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
}

.props-section { margin-bottom: 0.5rem; }

.props-section.hidden { display: none !important; }

/* Empty state */
.props-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.props-empty-state svg {
    width: 48px; height: 48px;
    opacity: 0.3;
}

.props-empty-state p {
    font-size: 0.85rem;
    line-height: 1.5;
    opacity: 0.7;
}

/* Section header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.section-header h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-secondary);
}

.reset-link {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s ease;
}

.reset-link:hover { color: var(--accent); }

/* ============================================
   FILTER CAROUSEL — Instagram-style visual thumbnails
   ============================================ */
.filter-carousel {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.filter-carousel::-webkit-scrollbar { display: none; }

.filter-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.filter-item:hover { transform: scale(1.05); }

.filter-item.active .filter-thumb-wrap {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.filter-item.active span { color: var(--accent); }

.filter-thumb-wrap {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid transparent;
    background: var(--bg-surface);
    position: relative;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.filter-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: filter 0.15s ease;
}

/* Placeholder gradient when no image loaded */
.filter-thumb:not([src]) {
    background: linear-gradient(135deg, #1a1a28, #2a1a3a);
}

.filter-item span {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: center;
    max-width: 60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s ease;
}

/* ============================================
   ADJUSTMENT SLIDERS
   ============================================ */
.filter-row { margin-bottom: 0.65rem; }

.filter-row label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

.filter-row label span { color: var(--text-primary); font-weight: 500; }

/* ============================================
   PROP ROWS
   ============================================ */
.prop-row { margin-bottom: 0.65rem; }

.prop-row label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

.prop-row label span { color: var(--text-primary); font-weight: 500; }

.prop-row.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    align-items: end;
}

.props-section select,
.props-section input[type="number"] {
    width: 100%;
    padding: 0.45rem 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: 'DM Sans', sans-serif;
    outline: none;
    transition: border-color 0.15s ease;
}

.props-section select:focus,
.props-section input[type="number"]:focus { border-color: var(--accent); }

.props-section input[type="color"] {
    width: 100%;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg-surface);
    padding: 3px;
}

.props-section input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.props-section input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }

/* Style button group (Bold, Italic, Align) */
.style-btn-group {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.style-btn {
    padding: 0.4rem 0.6rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'DM Sans', sans-serif;
    transition: all 0.15s ease;
    flex: 1;
    text-align: center;
    min-width: 36px;
}

.style-btn:hover { border-color: var(--accent); color: var(--accent); }

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

/* ============================================
   DRAW TOOL — Brush presets + swatches
   ============================================ */
.brush-presets {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.brush-preset {
    flex: 1;
    height: 44px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.brush-preset:hover { border-color: var(--accent); }

.brush-preset.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.brush-preset span {
    background: var(--text-primary);
    border-radius: 50%;
    display: block;
    flex-shrink: 0;
}

.color-swatches {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s ease, border-color 0.1s ease;
    flex-shrink: 0;
}

.color-swatch:hover { transform: scale(1.15); border-color: rgba(255,255,255,0.3); }
.color-swatch.active { border-color: var(--accent); transform: scale(1.1); }

/* ============================================
   RANGE INPUTS — Custom Styling
   ============================================ */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
    height: 20px;
}

input[type="range"]::-webkit-slider-runnable-track {
    background: var(--bg-surface);
    height: 4px;
    border-radius: 2px;
    border: none;
}

input[type="range"]::-moz-range-track {
    background: var(--bg-surface);
    height: 4px;
    border-radius: 2px;
    border: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    margin-top: -6px;
    border: none;
    box-shadow: 0 0 8px rgba(192, 132, 252, 0.5);
    transition: transform 0.1s ease;
}

input[type="range"]::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 8px rgba(192, 132, 252, 0.5);
    transition: transform 0.1s ease;
}

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

input[type="range"]:focus { outline: none; }

/* ============================================
   EXPORT MODAL
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.hidden { display: none !important; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-mid);
    border-radius: 18px;
    padding: 1.75rem;
    width: 360px;
    max-width: 100%;
    position: relative;
}

.modal-content h2 {
    font-family: 'Space Grotesk', sans-serif;
    margin-bottom: 1.25rem;
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-close {
    position: absolute;
    top: 1rem; right: 1rem;
    width: 32px; height: 32px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.format-options {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.format-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.85rem 0.5rem;
    background: var(--bg-surface);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'DM Sans', sans-serif;
    transition: all 0.15s ease;
}

.format-option svg { width: 20px; height: 20px; opacity: 0.7; }

.format-option span {
    font-size: 0.7rem;
    font-weight: 400;
    opacity: 0.7;
}

.format-option:hover { border-color: var(--accent); color: var(--accent); }

.format-option.selected {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.quality-slider { margin: 0.75rem 0; }

.quality-slider label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.quality-slider label span { color: var(--text-primary); }

.export-info { font-size: 0.8rem; color: var(--text-secondary); }

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    bottom: calc(var(--mobile-bar-h) + 0.75rem);
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.7rem 1.1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-mid);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.82rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    max-width: 300px;
    pointer-events: auto;
}

.toast.show { opacity: 1; transform: translateX(0); }
.toast.fade-out { opacity: 0; transform: translateX(20px); }

.toast.success { border-left: 3px solid var(--teal); }
.toast.error   { border-left: 3px solid var(--coral); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ============================================
   MOBILE BOTTOM TOOLBAR (≤900px)
   ============================================ */
.mobile-toolbar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--mobile-bar-h);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 150;
    padding: 0 0.5rem;
    justify-content: space-around;
    align-items: center;
}

.mobile-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.4rem 0.8rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 10px;
    transition: all 0.15s ease;
    min-width: 52px;
}

.mobile-tool-btn svg { width: 20px; height: 20px; }

.mobile-tool-btn span {
    font-size: 0.62rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.mobile-tool-btn:hover { color: var(--text-primary); }

.mobile-tool-btn.active {
    color: var(--accent);
}

.mobile-tool-btn.active svg {
    filter: drop-shadow(0 0 4px var(--accent));
}

/* ============================================
   MOBILE BOTTOM SHEET
   ============================================ */
.sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 160;
    transition: background 0.3s ease;
}

.sheet-backdrop.visible {
    display: block;
    background: rgba(0,0,0,0.5);
}

.mobile-sheet {
    position: fixed;
    bottom: var(--mobile-bar-h);
    left: 0; right: 0;
    z-index: 170;
    background: var(--bg-card);
    border-top: 1px solid var(--border-mid);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mobile-sheet.open { transform: translateY(0); }

.sheet-handle-bar {
    display: flex;
    justify-content: center;
    padding: 0.6rem 0 0.25rem;
    flex-shrink: 0;
    cursor: pointer;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border-mid);
    border-radius: 2px;
}

.sheet-content {
    padding: 0.5rem 1rem 1rem;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   RESPONSIVE — MOBILE (≤900px)
   ============================================ */
@media (max-width: 900px) {
    /* Hide desktop panels */
    .editor-toolbar { display: none !important; }
    .editor-properties { display: none !important; }

    /* Show mobile toolbar */
    .mobile-toolbar { display: flex; }

    /* Shrink canvas area for bottom bar — fixed layout, so just adjust bottom */
    .editor-body {
        bottom: var(--mobile-bar-h);
    }

    /* Toast container above bottom bar */
    .toast-container {
        bottom: calc(var(--mobile-bar-h) + 0.5rem);
        right: 0.5rem;
        left: 0.5rem;
    }

    /* Full-width toast on mobile */
    .toast { max-width: 100%; }

    /* Crop actions bar higher on mobile */
    .crop-actions-bar {
        bottom: 0.75rem;
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .crop-actions-bar .crop-hint { text-align: center; }

    .crop-action-btn { text-align: center; padding: 0.7rem 1rem; }

    /* Upload zone smaller on mobile */
    .upload-drop-zone { padding: 2rem 1.5rem; }

    /* Bigger touch targets */
    .mobile-tool-btn { min-width: 0; }
}

/* Extra small */
@media (max-width: 480px) {
    .logo { font-size: 1rem; }
    .upload-drop-zone h2 { font-size: 1rem; }
}

/* ============================================
   UTILITY
   ============================================ */
.hidden { display: none !important; }

/* ============================================
   TEMPLATE GALLERY
   ============================================ */
.template-gallery {
    position: absolute;
    inset: 0;
    background: var(--bg-dark);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 10;
    display: flex;
    flex-direction: column;
    padding: 0;
    -webkit-overflow-scrolling: touch;
}

.template-gallery.hidden { display: none !important; }

/* Header */
.tg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.75rem 1rem;
    flex-shrink: 0;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.tg-header-left { display: flex; flex-direction: column; gap: 0.2rem; }

.tg-headline {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tg-sub {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.tg-upload-own {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.tg-upload-own svg { width: 14px; height: 14px; }
.tg-upload-own input[type="file"] { display: none; }
.tg-upload-own:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* Grid */
.tg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1.5rem 1.75rem;
    flex: 1;
}

/* Card */
.tg-card {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    cursor: pointer;
    border-radius: 14px;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    outline: none;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
}

.tg-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
    border-color: var(--accent);
}

.tg-card:active { transform: translateY(-1px); }

.tg-card:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

/* Preview area */
.tg-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tg-prev-ig-post    { background: linear-gradient(135deg, #c084fc 0%, #f472b6 50%, #fb7185 100%); }
.tg-prev-ig-story   { background: linear-gradient(180deg, #7c3aed 0%, #c026d3 50%, #db2777 100%); }
.tg-prev-tiktok     { background: linear-gradient(180deg, #111 0%, #0a0a0f 40%, #1a0a2e 100%); }
.tg-prev-youtube    { background: linear-gradient(135deg, #111 0%, #1a0808 50%, #2d0a0a 100%); }
.tg-prev-facebook   { background: linear-gradient(135deg, #1877f2 0%, #1565c0 100%); }
.tg-prev-twitter    { background: linear-gradient(135deg, #0f0f0f 0%, #1a1a2e 100%); }
.tg-prev-blank      { background: var(--bg-surface); }

/* The inner frame that shows the layout mockup */
.tg-prev-frame {
    width: 80%;
    height: 80%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: flex-end;
    padding: 8px;
}

.tg-prev-story-frame {
    width: 55%;
    height: 90%;
    justify-content: flex-end;
}

.tg-prev-wide-frame {
    width: 90%;
    height: 75%;
    justify-content: flex-end;
}

.tg-prev-blank-frame {
    width: 80%;
    height: 80%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 2px dashed rgba(148,148,168,0.3);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Photo zone placeholder */
.tg-prev-photo-zone {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: rgba(255,255,255,0.6);
    font-size: 0.6rem;
    font-weight: 500;
    border: 1.5px dashed rgba(255,255,255,0.3);
    min-height: 40px;
    text-align: center;
}

.tg-prev-photo-tall { min-height: 80px; }
.tg-prev-photo-wide { min-height: 35px; }

/* Text placeholder blocks */
.tg-prev-text-row { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.tg-prev-sub-row { margin-top: 2px; }

.tg-prev-title-block {
    height: 8px;
    background: rgba(255,255,255,0.7);
    border-radius: 4px;
    width: 80%;
}

.tg-prev-sub-block {
    height: 5px;
    background: rgba(255,255,255,0.35);
    border-radius: 3px;
    width: 55%;
}

.tg-prev-story-text { justify-content: flex-start; padding-bottom: 2px; }
.tg-prev-yt-text { flex-direction: column; align-items: flex-start; gap: 3px; }

.tg-prev-yt-title {
    background: rgba(255,255,255,0.85);
    width: 90%;
    height: 9px;
}

.tg-prev-yt-sub {
    background: rgba(255,255,255,0.4);
    width: 60%;
    height: 5px;
}

.tg-prev-tiktok-title {
    background: rgba(255,255,255,0.9);
    height: 9px;
}

.tg-prev-tw-title {
    background: rgba(255,255,255,0.75);
    height: 8px;
}

/* Platform badge */
.tg-platform-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px;
    padding: 3px 8px 3px 5px;
    font-size: 0.62rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
}

.tg-badge-reels { background: linear-gradient(135deg, rgba(131,58,180,0.7), rgba(253,29,29,0.7)); }
.tg-badge-tiktok { background: rgba(0,0,0,0.7); }
.tg-badge-yt { background: rgba(255,0,0,0.6); }
.tg-badge-fb { background: rgba(24,119,242,0.7); }
.tg-badge-tw { background: rgba(0,0,0,0.7); }

/* Card info (name + dims) */
.tg-card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0.85rem 0.85rem;
}

.tg-card-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tg-card-dims {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Blank card special */
.tg-card-blank .tg-preview {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

/* Back to templates link */
.tg-back-link {
    margin-top: 0.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    transition: color 0.15s ease;
    font-family: 'DM Sans', sans-serif;
}

.tg-back-link:hover { color: var(--accent); }

/* ============================================
   TEMPLATE GALLERY — MOBILE
   ============================================ */
@media (max-width: 900px) {
    .tg-header {
        padding: 1rem;
        flex-direction: row;
        align-items: flex-start;
    }

    .tg-headline { font-size: 1.1rem; }

    .tg-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 1rem;
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .tg-upload-own span { display: none; }
    .tg-headline { font-size: 1rem; }
    .tg-sub { display: none; }
}
