:root {
    /* Base Themes - Dark */
    --bg-page: #09090b; /* Zinc 950 */
    --bg-panel: rgba(24, 24, 27, 0.7); /* Zinc 900 Glass */
    --bg-surface: #27272a; /* Zinc 800 */
    --bg-hover: #3f3f46;
    
    --text-primary: #fafafa;
    --text-muted: #a1a1aa;
    
    --border-color: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    
    --primary: #8b5cf6; /* Violet 500 */
    --primary-hover: #7c3aed;
    --primary-light: rgba(139, 92, 246, 0.15);
    
    --handle-color: #ffffff;
    --handle-border: #8b5cf6;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'Fira Code', monospace;
}

[data-theme="light"] {
    --bg-page: #f4f4f5; /* Zinc 100 */
    --bg-panel: rgba(255, 255, 255, 0.8);
    --bg-surface: #e4e4e7;
    --bg-hover: #d4d4d8;
    
    --text-primary: #09090b;
    --text-muted: #52525b;
    
    --border-color: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.2);
    
    --primary: #6d28d9;
    --primary-hover: #5b21b6;
    --primary-light: rgba(109, 40, 217, 0.1);
    
    --handle-color: #ffffff;
    --handle-border: #6d28d9;
    
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

/* Utilities */
.font-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }

/* Layout */
.app-layout {
    width: 100%;
    max-width: 1400px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100vh;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    border-radius: var(--radius-md);
    display: flex; justify-content: center; align-items: center;
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}
.logo-icon i { width: 22px; height: 22px; }

.brand-text h1 { font-size: 1.25rem; font-weight: 700; background: linear-gradient(to right, var(--primary), #ec4899); -webkit-background-clip: text; -webkit-text-fill-color: transparent;}
.subtitle { font-size: 0.8rem; color: var(--text-muted); font-weight: 500;}

.header-actions {
    display: flex; align-items: center; gap: 0.5rem;
}

/* Base Inputs & Buttons */
.btn {
    display: inline-flex; justify-content: center; align-items: center; gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem; font-weight: 600; font-family: inherit;
    border: 1px solid transparent; cursor: pointer; transition: all 0.2s;
}
.btn i { width: 16px; height: 16px; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-primary { background: linear-gradient(135deg, var(--primary), #ec4899); color: white; border: none; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-ghost { background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-ghost:hover { border-color: var(--text-muted); }
.icon-btn {
    width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-md); border: none; background: transparent; color: var(--text-muted);
    cursor: pointer; transition: 0.2s;
}
.icon-btn:hover { background: var(--bg-surface); color: var(--text-primary); }

/* Workspace Grid */
.workspace {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* Panels */
.glass-panel {
    background: var(--bg-panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); display: flex; flex-direction: column; overflow: hidden;
}

.panel-section {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}
.panel-section:last-child { border-bottom: none; }
.panel-section h3 { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 1rem; }
.flex-1 { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-header h3 { margin-bottom: 0; }

/* Left Sidebar - Options */
.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.shape-btn {
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md);
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); cursor: pointer; transition: 0.2s;
}
.shape-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
.shape-btn.active { color: var(--primary); border-color: var(--primary); background: var(--primary-light); }

.presets-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; max-height: 300px; overflow-y: auto; padding-right: 0.5rem; }
.preset-item {
    background: var(--bg-page); border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    padding: 0.5rem; font-size: 0.8rem; color: var(--text-primary); cursor: pointer; text-align: center;
    transition: 0.2s; font-weight: 500;
}
.preset-item:hover { border-color: var(--primary); background: var(--primary-light); }

.bg-picker-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem; }
.bg-btn {
    aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--border-color); cursor: pointer;
    background-size: cover; background-position: center; transition: 0.2s;
}
.bg-btn:hover, .bg-btn.active { border-color: var(--text-primary); transform: scale(1.1); }

/* Center - Preview Playground */
.preview-panel {
    background: var(--bg-page); border: 1px solid var(--border-color); border-radius: var(--radius-lg);
    display: flex; flex-direction: column; overflow: hidden; position: relative;
    background-image: radial-gradient(var(--border-strong) 1px, transparent 1px);
    background-size: 20px 20px;
}
.preview-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem; background: var(--bg-panel); border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); z-index: 10;
}
.toolbar-label { font-weight: 600; font-size: 0.9rem; }
.toolbar-controls { display: flex; align-items: center; gap: 1rem; }
.toggle-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-muted); cursor: pointer; }

.preview-area {
    flex: 1; display: flex; align-items: center; justify-content: center; position: relative;
}
.demo-box {
    width: 300px; height: 300px;
    background: linear-gradient(135deg, #6366f1, #a855f7); /* Default */
    transition: clip-path 0.1s;
    /* Optional: add a subtle drop shadow to visualize the raw boundary */
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
}

.handles-container {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; /* Let clicks pass through except on handles */
}
/* Visual box for coordinate mapping */
.handles-box {
    position: absolute; width: 300px; height: 300px;
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    pointer-events: none;
}
.handle {
    position: absolute; width: 14px; height: 14px; margin-top: -7px; margin-left: -7px;
    background: var(--handle-color); border: 2px solid var(--handle-border);
    border-radius: 50%; cursor: grab; pointer-events: auto;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5); z-index: 100;
}
.handle:active { cursor: grabbing; transform: scale(1.2); }
.handle.active-handle { background: var(--primary); transform: scale(1.2); }

.controls-hint {
    padding: 1rem; text-align: center; color: var(--text-muted); font-size: 0.8rem;
    background: var(--bg-panel); border-top: 1px solid var(--border-color);
}

/* Right Sidebar - Output */
.output-panel { }

.code-editor-wrapper {
    flex: 1; background: var(--bg-page); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); padding: 1rem; overflow: hidden; display: flex;
}
.code-editor {
    width: 100%; height: 100%; resize: none; border: none; background: transparent;
    color: var(--primary); font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.6;
    outline: none;
}

.history-list {
    display: flex; flex-direction: column; gap: 0.5rem; max-height: 150px; overflow-y: auto;
}
.history-item {
    padding: 0.5rem; background: var(--bg-page); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); font-size: 0.8rem; font-family: var(--font-mono);
    cursor: pointer; display: flex; justify-content: space-between; align-items: center;
}
.history-item:hover { border-color: var(--primary); }
.empty-history { text-align: center; padding: 1rem 0; font-size: 0.85rem; }

/* Modals & Toasts (Standard Layouts) */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 1000;
    display: none; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.2s forwards; }

.modal {
    width: 100%; max-width: 450px; background: var(--bg-panel); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); padding: 1.5rem; animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);}
.modal-header h2 { font-size: 1.1rem; display: flex; align-items: center; gap: 0.5rem; }
.modal-close { margin-top: -0.5rem; margin-right: -0.5rem; }
.shortcuts-list { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }
.shortcuts-list li { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; color: var(--text-muted); }
kbd { background: var(--bg-surface); border: 1px solid var(--border-color); padding: 0.2rem 0.4rem; border-radius: 4px; font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-primary); }

.toast {
    position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--text-primary); color: var(--bg-page); padding: 0.75rem 1.5rem; border-radius: 99px;
    font-weight: 600; font-size: 0.9rem; box-shadow: var(--shadow-md); z-index: 2000;
    opacity: 0; transition: all 0.3s; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

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

/* Media Queries */
@media (max-width: 1100px) {
    .workspace { grid-template-columns: 1fr; grid-template-rows: auto 400px auto; }
}
