:root {
    --bg-main: #0A0A1A;
    --bg-surface: rgba(255, 255, 255, 0.03);
    --bg-surface-hover: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --secondary: #818CF8;
    --accent: #F43F5E;
    
    --text-primary: #F8FAFC;
    --text-muted: #94A3B8;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 24px;
    
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Glassmorphism utility */
.glass {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(8px);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.actions {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    font-family: inherit;
}

.btn.primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

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

.btn.secondary:hover {
    background: var(--bg-surface-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn.icon-btn {
    padding: 0.5rem;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 65px);
}

.controls {
    width: 340px;
    min-width: 340px;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-group h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    padding: 0.25rem;
    border: 1px solid var(--border-color);
}

.tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Inputs */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group.row {
    flex-direction: row;
    gap: 1rem;
}

.input-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="url"],
textarea,
select {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color var(--transition);
    resize: vertical;
}

input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Color Picker */
.color-picker-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

input[type="color"] {
    -webkit-appearance: none;
    width: 100%;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    cursor: pointer;
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* File Upload */
.file-upload {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.upload-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-surface);
    border: 1px dashed var(--primary);
    color: var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
}

.upload-btn:hover {
    background: rgba(99, 102, 241, 0.1);
}

/* Preview Area */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background-color: #05050A;
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 24px 24px;
    position: relative;
    overflow: hidden;
}

.canvas-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.canvas-scale-container {
    /* We use JS to set transform: scale() here based on window size */
    transform-origin: center center;
    transition: transform 0.1s ease-out;
}

/* The actual 1200x630 canvas */
.og-canvas {
    width: 1200px;
    height: 630px;
    background: #0f172a; /* Fallback */
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0; /* OG images typically have no border radius */
}

/* Background element */
.canvas-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    /* Updated dynamically */
}

/* Content Container */
.canvas-content {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    padding: 80px;
    color: white;
}

/* 
 * TEMPLATES STYLING 
 */

/* Blog Template */
.og-canvas.template-blog .canvas-content {
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
}

.og-canvas.template-blog .og-logo {
    position: absolute;
    top: 60px;
    left: 80px;
    height: 60px;
    max-width: 250px;
    object-fit: contain;
}

.og-canvas.template-blog .og-title {
    font-size: 84px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin-bottom: 24px;
    max-width: 900px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.og-canvas.template-blog .og-subtitle {
    font-size: 32px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    border-left: 4px solid var(--accent);
    padding-left: 20px;
}

/* Product Template */
.og-canvas.template-product .canvas-content {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.og-canvas.template-product .product-info {
    flex: 1;
    max-width: 600px;
}

.og-canvas.template-product .og-subtitle {
    font-size: 36px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.og-canvas.template-product .og-title {
    font-size: 72px;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 40px;
}

.og-canvas.template-product .og-price {
    font-size: 48px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    display: inline-block;
    padding: 12px 32px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.og-canvas.template-product .product-visual {
    width: 400px;
    height: 400px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.og-canvas.template-product .og-logo {
    max-width: 80%;
    max-height: 80%;
    object-fit: contain;
}

/* Event Template */
.og-canvas.template-event .canvas-content {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.og-canvas.template-event .og-logo {
    height: 80px;
    margin-bottom: 60px;
}

.og-canvas.template-event .og-title {
    font-size: 96px;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 40px;
    letter-spacing: -0.03em;
}

.og-canvas.template-event .event-details {
    display: flex;
    gap: 40px;
    background: rgba(0, 0, 0, 0.3);
    padding: 24px 48px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.og-canvas.template-event .detail-item {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 32px;
    font-weight: 500;
}

.og-canvas.template-event .detail-item svg {
    width: 36px;
    height: 36px;
    color: var(--accent);
}

/* Preview Info box */
.preview-info {
    position: absolute;
    bottom: 24px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-surface);
    backdrop-filter: blur(8px);
    padding: 0.5rem 1rem;
    border-radius: 100px;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.preview-info svg {
    width: 16px;
    height: 16px;
}


/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    width: 90%;
    max-width: 600px;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.hidden .modal {
    transform: translateY(20px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    color: var(--text-muted);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.code-block {
    position: relative;
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow-x: auto;
}

.code-block pre {
    font-family: monospace;
    font-size: 0.875rem;
    color: #A5B4FC;
    line-height: 1.5;
    white-space: pre-wrap;
}

.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(255, 255, 255, 0.1) !important;
}

.mt-4 {
    margin-top: 1.5rem;
}

/* Loading Overlay */
#loading-overlay {
    z-index: 200;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: white;
}

.loading-spinner svg {
    width: 48px;
    height: 48px;
    color: var(--primary);
}

.spin {
    animation: spin 1s linear infinite;
}

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

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .controls {
        width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 50vh;
    }
}
