:root {
    /* Base Theme */
    --bg-dark: #0F0A1A;
    --bg-panel: rgba(25, 18, 43, 0.6);
    --bg-element: rgba(45, 30, 80, 0.4);
    --text-main: #FFFFFF;
    --text-muted: #A094B8;
    --border-color: rgba(139, 92, 246, 0.2);
    
    /* Vibrant Purple Palette (Default) */
    --primary: #8B5CF6;
    --secondary: #A78BFA;
    --accent: #F472B6;
    --primary-hover: #7C3AED;
    
    /* Layout & Styling */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Theme Options */
.theme-ocean-blue {
    --primary: #3B82F6;
    --secondary: #60A5FA;
    --accent: #38BDF8;
    --primary-hover: #2563EB;
    --border-color: rgba(59, 130, 246, 0.2);
    --bg-panel: rgba(15, 23, 42, 0.6);
    --bg-element: rgba(30, 58, 138, 0.4);
}

.theme-emerald-green {
    --primary: #10B981;
    --secondary: #34D399;
    --accent: #6EE7B7;
    --primary-hover: #059669;
    --border-color: rgba(16, 185, 129, 0.2);
    --bg-panel: rgba(6, 24, 20, 0.6);
    --bg-element: rgba(6, 78, 59, 0.4);
}

.theme-sunset-orange {
    --primary: #F97316;
    --secondary: #FB923C;
    --accent: #FCD34D;
    --primary-hover: #EA580C;
    --border-color: rgba(249, 115, 22, 0.2);
    --bg-panel: rgba(43, 20, 10, 0.6);
    --bg-element: rgba(124, 45, 18, 0.4);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden; /* Prevent body scroll, handle inside containers */
    height: 100vh;
}

/* Base Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-secondary {
    background: var(--bg-element);
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--primary);
}

.btn-icon {
    padding: 8px;
    background: var(--bg-element);
    color: var(--text-muted);
    border-color: var(--border-color);
    border-radius: var(--radius-sm);
}

.btn-icon.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-icon:hover:not(.active) {
    color: var(--text-main);
    background: rgba(255,255,255,0.1);
}

input[type="text"] {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition);
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 24px;
    overflow-y: auto;
    z-index: 10;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text; /* standard property added */
    color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.control-group h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.template-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: 12px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-results {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.search-results::-webkit-scrollbar {
    width: 6px;
}
.search-results::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

/* Tech Item Drag/Drop */
.tech-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: transform var(--transition);
    user-select: none;
}

.tech-item:active {
    cursor: grabbing;
}

.tech-item:hover {
    border-color: var(--primary);
    transform: translateX(4px);
}

.tech-icon {
    font-size: 1.5rem;
    color: var(--text-main);
    width: 24px;
    text-align: center;
}

.tech-info {
    flex: 1;
}

.tech-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.tech-category {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.tech-add-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    transition: color var(--transition);
}

.tech-add-btn:hover {
    color: var(--accent);
}

/* Toggles */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    cursor: pointer;
}

.toggle-switch input[type="checkbox"] {
    appearance: none;
    width: 40px;
    height: 20px;
    background: var(--bg-element);
    border-radius: 20px;
    position: relative;
    outline: none;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: all var(--transition);
}

.toggle-switch input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

.toggle-switch input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-switch input[type="checkbox"]:checked::after {
    left: 22px;
    background: white;
}

.toggle-switch label {
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    user-select: none;
}

/* Layout Options */
.layout-toggle {
    display: flex;
    gap: 8px;
}

.export-actions {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at center, rgba(139, 92, 246, 0.05) 0%, transparent 70%);
    position: relative;
}

.workspace::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: 0;
    pointer-events: none;
}

.workspace-toolbar {
    padding: 24px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1;
}

.stack-title {
    font-size: 2rem;
    outline: none;
    border-bottom: 2px solid transparent;
    transition: border-color var(--transition);
    padding-bottom: 4px;
}

.stack-title:focus {
    border-bottom-color: var(--primary);
}

.theme-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-panel);
    padding: 8px 16px;
    border-radius: 30px;
    border: 1px solid var(--border-color);
}

.theme-selector span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.color-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform var(--transition);
}

.color-btn.active {
    box-shadow: 0 0 0 2px var(--bg-dark), 0 0 0 4px var(--primary);
}

.color-btn:hover {
    transform: scale(1.2);
}

/* Canvas Area */
.canvas-container {
    flex: 1;
    padding: 0 40px 40px 40px;
    display: flex;
    flex-direction: column;
    z-index: 1;
    overflow-y: auto;
}

.stack-canvas {
    background: rgba(15, 10, 26, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    min-height: 400px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 32px;
    box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

/* Categories in Canvas */
.canvas-category {
    background: rgba(255,255,255,0.02);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    min-height: 120px;
    position: relative;
    transition: all var(--transition);
}

.canvas-category.sortable-ghost {
    opacity: 0.4;
}

.canvas-category h4 {
    position: absolute;
    top: -12px;
    left: 24px;
    background: var(--bg-dark);
    padding: 0 12px;
    font-size: 0.85rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

/* Category Grid Layout */
.stack-canvas.layout-grid {
    flex-direction: column;
}
.stack-canvas.layout-grid .category-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    min-height: 60px;
}

/* Layered Layout */
.stack-canvas.layout-layered {
    align-items: center;
    justify-content: center;
}
.stack-canvas.layout-layered .canvas-category {
    width: 80%;
    text-align: center;
}
.stack-canvas.layout-layered .category-items {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    min-height: 60px;
}

/* Node Item on Canvas */
.canvas-node {
    background: linear-gradient(145deg, var(--bg-element), rgba(255,255,255,0.05));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    position: relative;
    cursor: grab;
    transition: all var(--transition);
}

.canvas-node:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.canvas-node i {
    font-size: 2.5rem;
    color: var(--primary);
}

.canvas-node span {
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
}

.node-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #EF4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: all var(--transition);
}

.canvas-node:hover .node-remove {
    opacity: 1;
    transform: scale(1);
}

/* Proficiency Indicators */
.proficiency-bar {
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
    display: none;
}

.show-proficiency .proficiency-bar {
    display: block;
}

.proficiency-level {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}
.level-1 { width: 33%; background: #FCD34D;}
.level-2 { width: 66%; background: var(--secondary);}
.level-3 { width: 100%; background: var(--primary);}

/* Level selector overlay */
.level-selector {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    display: flex;
    gap: 4px;
    padding: 4px;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition);
    z-index: 5;
}

.show-proficiency .canvas-node:hover .level-selector {
    opacity: 1;
    pointer-events: auto;
    bottom: -40px;
}

.lvl-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
}

.lvl-btn:hover { background: var(--primary); }

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 16px;
    min-height: 300px;
}

.empty-state i {
    font-size: 3rem;
    opacity: 0.5;
}

/* Animations */
@keyframes floatUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseBorder {
    0% { border-color: rgba(139, 92, 246, 0.2); }
    50% { border-color: rgba(139, 92, 246, 0.8); }
    100% { border-color: rgba(139, 92, 246, 0.2); }
}

.animations-enabled .canvas-node {
    animation: floatUp 0.4s ease forwards;
}

/* Embed Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-dark);
    padding: 32px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 600px;
    position: relative;
    transform: translateY(20px);
    transition: transform var(--transition);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px; right: 16px;
    background: none; border: none;
    color: var(--text-muted);
    font-size: 1.2rem; cursor: pointer;
}

.modal-content h2 { margin-bottom: 8px; }
.modal-content p { color: var(--text-muted); margin-bottom: 24px; }

.code-block {
    background: #000;
    border-radius: var(--radius-sm);
    padding: 16px;
    position: relative;
}

code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    color: #A78BFA;
    white-space: pre-wrap;
    word-break: break-all;
}

.btn-copy {
    position: absolute;
    top: 8px; right: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 900px) {
    .app-container { flex-direction: column; }
    .sidebar { width: 100%; height: 40vh; border-right: none; border-bottom: 1px solid var(--border-color); }
    .workspace { height: 60vh; }
    .workspace-toolbar { padding: 16px; flex-direction: column; gap: 12px; }
    .canvas-container { padding: 16px; }
    .stack-canvas { padding: 20px; }
}
