/* CSS Variables for theming */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-hover: rgba(255, 255, 255, 0.08);
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --accent-glow: rgba(99, 102, 241, 0.4);
    --text-primary: #f8fafc;
    --text-secondary: rgba(248, 250, 252, 0.7);
    --text-muted: rgba(248, 250, 252, 0.5);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.3);
    --error: #ef4444;
    --error-glow: rgba(239, 68, 68, 0.3);
    --warning: #f59e0b;
    --border-radius: 12px;
    --border-radius-lg: 16px;
    --border-radius-sm: 8px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --blur-amount: 20px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px var(--accent-glow);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Animated background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse 80% 50% at 20% 40%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 80% 60%, rgba(139, 92, 246, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse 50% 30% at 50% 80%, rgba(168, 85, 247, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
    animation: backgroundPulse 15s ease-in-out infinite;
}

@keyframes backgroundPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: fadeInUp 0.6s var(--transition-slow);
}

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

header {
    background: var(--accent-gradient);
    color: white;
    padding: 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.1) 50%, transparent 100%);
    animation: headerShine 3s ease-in-out infinite;
}

@keyframes headerShine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
    letter-spacing: -0.5px;
    position: relative;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
    position: relative;
    font-weight: 400;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px;
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.tool-section {
    flex: 1;
    min-width: 200px;
    animation: fadeIn 0.4s ease-out;
    animation-fill-mode: both;
}

.tool-section:nth-child(1) { animation-delay: 0.1s; }
.tool-section:nth-child(2) { animation-delay: 0.15s; }
.tool-section:nth-child(3) { animation-delay: 0.2s; }
.tool-section:nth-child(4) { animation-delay: 0.25s; }
.tool-section:nth-child(5) { animation-delay: 0.3s; }

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

.tool-section h3 {
    font-size: 0.75em;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-section h3::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 12px;
    background: var(--accent-gradient);
    border-radius: 2px;
}

.tool-btn, .action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin: 6px 0;
    width: 100%;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.tool-btn::before, .action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left var(--transition-slow);
}

.tool-btn:hover::before, .action-btn:hover::before {
    left: 100%;
}

.tool-btn:hover, .action-btn:hover {
    background: var(--glass-hover);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.tool-btn.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-glow);
}

.tool-btn svg, .action-btn svg {
    transition: transform var(--transition-fast);
}

.tool-btn:hover svg, .action-btn:hover svg {
    transform: scale(1.1);
}

.atom-buttons, .bond-buttons, .functional-group-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.atom-btn, .bond-type-btn, .fg-btn {
    padding: 10px 14px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    transition: all var(--transition-normal);
    min-width: 50px;
    position: relative;
    overflow: hidden;
}

.atom-btn:hover, .bond-type-btn:hover, .fg-btn:hover {
    background: var(--glass-hover);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--shadow-sm);
}

.atom-btn.active, .bond-type-btn.active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 0 20px var(--success-glow);
}

.fg-btn:hover {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    border-color: transparent;
}

.bond-type-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.bond-type-btn svg {
    stroke: var(--text-primary);
    transition: all var(--transition-fast);
}

.bond-type-btn:hover svg {
    stroke: white;
}

.bond-type-btn.active svg {
    stroke: white;
}

.canvas-container {
    position: relative;
    background: var(--bg-secondary);
    padding: 24px;
    max-height: 900px;
    overflow: auto;
}

#canvas {
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    display: block;
    margin: 0 auto;
    background: #ffffff;
    cursor: crosshair;
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(255, 255, 255, 0.05);
    transition: box-shadow var(--transition-normal);
}

#canvas:hover {
    box-shadow: var(--shadow-lg), 0 0 60px rgba(99, 102, 241, 0.1);
}

.canvas-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
}

#coordsDisplay, #statusDisplay {
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.instructions {
    padding: 30px;
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
}

.instructions h3 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.2em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.instructions h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 20px;
    background: var(--accent-gradient);
    border-radius: 2px;
}

.instructions ul {
    list-style: none;
    padding: 0;
    display: grid;
    gap: 8px;
}

.instructions li {
    padding: 14px 18px;
    color: var(--text-secondary);
    line-height: 1.6;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-normal);
}

.instructions li:hover {
    background: var(--glass-hover);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
}

.instructions strong {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Keyboard shortcuts hint */
.keyboard-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px;
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.shortcut-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 24px;
    padding: 0 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Zoom controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    margin-top: 12px;
}

.zoom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.zoom-btn:hover {
    background: var(--glass-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.zoom-level {
    font-family: 'SF Mono', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* Template buttons */
.template-btn {
    padding: 10px 14px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all var(--transition-normal);
}

.template-btn:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-2px);
}

/* Responsive Design */
@media (max-width: 1024px) {
    #canvas {
        width: 100%;
        height: auto;
    }
    
    .toolbar {
        flex-direction: column;
    }
    
    .tool-section {
        min-width: 100%;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.8em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    body {
        padding: 10px;
    }
    
    .instructions ul {
        grid-template-columns: 1fr;
    }
}

/* Notification styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    border-radius: var(--border-radius);
    border: 1px solid var(--success);
    box-shadow: var(--shadow-md), 0 0 30px var(--success-glow);
    z-index: 1000;
    animation: slideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.notification::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--success);
    animation: pulse 2s ease-in-out infinite;
}

.notification.error {
    border-color: var(--error);
    box-shadow: var(--shadow-md), 0 0 30px var(--error-glow);
}

.notification.error::before {
    background: var(--error);
    box-shadow: 0 0 10px var(--error);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.9); }
}

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

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Focus states for accessibility */
.tool-btn:focus, .action-btn:focus, .atom-btn:focus, 
.bond-type-btn:focus, .fg-btn:focus, .template-btn:focus,
.zoom-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-primary), 0 0 0 4px rgba(99, 102, 241, 0.3);
}

/* Loading animation */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.loading {
    background: linear-gradient(90deg, var(--glass-bg) 25%, var(--glass-hover) 50%, var(--glass-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* Tooltip styles */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 100;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

/* Undo/Redo buttons */
.history-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.history-btn:hover:not(:disabled) {
    background: var(--glass-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.history-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.history-btn svg {
    width: 18px;
    height: 18px;
}

/* Toggle switch for snap bonds mode */
.mode-toggle {
    display: flex;
    align-items: center;
    padding: 8px 0;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    transition: all var(--transition-normal);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all var(--transition-normal);
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider {
    background: var(--accent-gradient);
    border-color: transparent;
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: white;
}

.toggle-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Size slider control */
.size-control {
    padding: 8px 0;
}

.size-label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.size-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

#atomSizeValue {
    color: var(--accent-primary);
    font-weight: 600;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    transition: all var(--transition-normal);
}

input[type="range"]:hover {
    background: var(--glass-hover);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--accent-glow);
    transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--accent-glow);
    transition: all var(--transition-fast);
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--accent-glow);
}
