:root {
    /* Color System - Light Theme (Default) */
    --primary-50: #f0f9ff;
    --primary-100: #e0f2fe;
    --primary-500: #0ea5e9;
    --primary-600: #0284c7;
    --primary-700: #0369a1;

    --accent-500: #f59e0b;
    --accent-600: #d97706;

    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    --danger-500: #ef4444;
    --danger-600: #dc2626;

    /* Semantic Colors */
    --primary-color: var(--primary-600);
    --primary-hover: var(--primary-700);
    --accent-color: var(--accent-500);
    
    --text-main: var(--slate-800);
    --text-muted: var(--slate-500);
    --text-light: var(--slate-400);
    
    --bg-body: var(--slate-50);
    --bg-surface: #ffffff;
    --bg-surface-alt: var(--slate-50);
    --bg-overlay: rgba(255, 255, 255, 0.85);
    
    --border-light: var(--slate-200);
    --shadow-color: 0, 0, 0;

    /* Background Image */
    --bg-image: url('https://images.unsplash.com/photo-1557683316-973673baf926?auto=format&fit=crop&q=80');

    /* Spacing & Layout */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --shadow-sm: 0 1px 2px 0 rgba(var(--shadow-color), 0.05);
    --shadow-md: 0 4px 6px -1px rgba(var(--shadow-color), 0.1), 0 2px 4px -1px rgba(var(--shadow-color), 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(var(--shadow-color), 0.1), 0 4px 6px -2px rgba(var(--shadow-color), 0.05);
    --shadow-glow: 0 0 20px rgba(14, 165, 233, 0.15);

    --header-height: 70px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --primary-color: var(--primary-500);
    --primary-hover: var(--primary-600);
    
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    
    --bg-body: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-alt: #0f172a;
    --bg-overlay: rgba(30, 41, 59, 0.85);
    
    --border-light: #334155;
    --shadow-color: 0, 0, 0;

    /* Dark Mode Background Image */
    --bg-image: url('https://images.unsplash.com/photo-1614850523459-c2f4c699c52e?auto=format&fit=crop&q=80');
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--slate-300);
    border-radius: 4px;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--slate-700);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--slate-400);
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: rgba(255, 255, 255, 0.5); /* Subtle overlay for content readability */
}
[data-theme="dark"] .app-container {
    background: rgba(15, 23, 42, 0.7);
}

/* Modern Navbar */
.navbar {
    height: var(--header-height);
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-light);
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--primary-color);
    filter: drop-shadow(0 2px 4px rgba(14, 165, 233, 0.2));
}

.brand-name {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-600), var(--primary-500));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}
[data-theme="dark"] .brand-name {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 32px;
    padding: 32px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.workspace {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: sticky;
    top: calc(var(--header-height) + 32px);
    height: calc(100vh - var(--header-height) - 64px);
    overflow-y: auto;
}

/* Cards & Panels */
.editor-panel, .preview-panel, .control-panel, .history-panel {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-panel {
    box-shadow: var(--shadow-md);
    flex: 1;
    min-height: 500px;
}

.panel-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.panel-header h3, .panel-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-title {
    margin-bottom: 16px;
    font-size: 15px;
}

/* Editor */
.editor-panel {
    height: 300px;
    transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}
.editor-panel:focus-within {
    box-shadow: var(--shadow-glow);
    border-color: var(--primary-500);
}

.editor-textarea {
    flex: 1;
    width: 100%;
    padding: 24px;
    border: none;
    resize: none;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-main);
    background: transparent;
}
.editor-textarea:focus {
    outline: none;
}
.editor-textarea::placeholder {
    color: var(--text-light);
}

/* Canvas Area */
.canvas-container {
    flex: 1;
    position: relative;
    background: radial-gradient(circle at center, var(--bg-surface) 0%, var(--bg-surface-alt) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: background 0.3s ease;
}

.empty-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-light);
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-500));
    color: white;
    box-shadow: 0 2px 4px rgba(14, 165, 233, 0.25);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-700), var(--primary-600));
    box-shadow: 0 4px 8px rgba(14, 165, 233, 0.35);
    transform: translateY(-1px);
}
[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
}

.btn-text {
    background: transparent;
    color: var(--text-muted);
}
.btn-text:hover {
    background: var(--slate-100);
    color: var(--text-main);
}
[data-theme="dark"] .btn-text:hover {
    background: var(--slate-800);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
}
.btn-icon:hover {
    background: var(--primary-50);
    color: var(--primary-600);
    border-color: var(--primary-100);
}
[data-theme="dark"] .btn-icon:hover {
    background: rgba(14, 165, 233, 0.1);
    border-color: rgba(14, 165, 233, 0.2);
}
.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: transparent;
    border-color: transparent;
}

/* Form Controls */
.control-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 14px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    transition: var(--transition-fast);
}
[data-theme="dark"] .control-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}
.control-select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

/* History List */
.history-list {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition-fast);
    position: relative;
}
.history-item:hover {
    border-color: var(--primary-600);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
[data-theme="dark"] .history-item:hover {
    border-color: var(--primary-500);
}

.history-thumbnail {
    height: 120px;
    background: var(--bg-surface-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-light);
}

.history-info {
    padding: 12px;
}
.history-time {
    font-size: 11px;
    color: var(--text-light);
    margin-bottom: 4px;
}
.history-text {
    font-size: 13px;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 12px;
}
.history-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.history-actions .btn {
    padding: 6px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}
.btn-danger-ghost {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-600);
}
.btn-danger-ghost:hover {
    background: rgba(239, 68, 68, 0.2);
}
[data-theme="dark"] .btn-danger-ghost {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}
.toast {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    padding: 16px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideIn 0.3s ease;
    pointer-events: auto;
    border-left: 4px solid var(--primary-500);
    color: var(--text-main);
}
.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: var(--danger-500); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
[data-theme="dark"] .loading-overlay {
    background: rgba(15, 23, 42, 0.9);
}
.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.loading-overlay p {
    color: var(--text-main);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--slate-200);
    border-top-color: var(--primary-600);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}
[data-theme="dark"] .spinner {
    border-color: var(--slate-700);
    border-top-color: var(--primary-500);
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Footer */
.footer {
    margin-top: auto;
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-light);
    padding: 40px 0;
    color: var(--text-muted);
}
.footer-content {
    text-align: center;
}
.footer-info a {
    color: var(--primary-600);
    text-decoration: none;
    transition: color 0.2s;
}
.footer-info a:hover {
    color: var(--primary-700);
}
[data-theme="dark"] .footer-info a {
    color: var(--primary-500);
}
[data-theme="dark"] .footer-info a:hover {
    color: var(--primary-400);
}

/* Responsive */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        padding: 24px;
    }
    .sidebar {
        position: static;
        height: auto;
        overflow: visible;
    }
}

@media (max-width: 640px) {
    .navbar {
        padding: 0 16px;
    }
    .main-content {
        padding: 16px;
    }
    .editor-panel {
        height: 240px;
    }
    .preview-panel {
        min-height: 400px;
    }
}
