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

:root {
    --bg-primary: #1f1f1f;
    --bg-secondary: #2d2d30;
    --bg-tertiary: #3c3c3c;
    --text-primary: #cccccc;
    --text-secondary: #969696;
    --accent-primary: #0078d4;
    --accent-hover: #106ebe;
    --accent-light: #4fc3f7;
    --border-color: #464647;
    --error-color: #f14c4c;
    --success-color: #89d185;
    --warning-color: #ffcc02;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);
    --radius: 6px;
    --radius-lg: 8px;
}

[data-theme="light"] {
    --bg-primary: #fefcfc;
    --bg-secondary: #fdf7f7;
    --bg-tertiary: #fbf0f0;
    --text-primary: #2d1b1b;
    --text-secondary: #7a6666;
    --accent-primary: #d4837a;
    --accent-hover: #c76f65;
    --accent-light: #e4a299;
    --border-color: #f2d6d6;
    --error-color: #e57373;
    --success-color: #81c784;
    --warning-color: #ffb74d;
    --shadow: 0 2px 8px rgba(212, 131, 122, 0.15);
    --shadow-lg: 0 4px 16px rgba(212, 131, 122, 0.25);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
}

.header {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    padding: 2rem 0;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.header-top {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

.theme-toggle {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.theme-toggle:hover {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-block;
}

.typing-text {
    display: inline-block;
    white-space: nowrap;
    border-right: 2px solid transparent;
    padding-right: 2px;
    min-height: 1.2em;
}

.cursor {
    display: none;
}

@keyframes blink-caret {
    from, to {
        border-color: var(--accent-primary);
    }
    50% {
        border-color: transparent;
    }
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 400;
}

.main {
    flex: 1;
    padding: 2rem 0;
}

.form-section {
    margin-bottom: 3rem;
}

.form-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.form-container h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-weight: 600;
}

.snippet-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.language-dropdown-container {
    position: relative;
}

.language-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.language-dropdown::-webkit-scrollbar {
    width: 6px;
}

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

.language-dropdown::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.language-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.language-option {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

.language-option:hover,
.language-option.highlighted {
    background: var(--bg-secondary);
}

.language-option:last-child {
    border-bottom: none;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    resize: vertical;
    min-height: 120px;
}

.save-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    align-self: flex-start;
}

.save-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.save-btn:active {
    transform: translateY(0);
}

.save-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

.controls-section {
    margin-bottom: 2rem;
}

.controls-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-group {
    flex: 1;
    max-width: 400px;
}

.search-group label {
    display: block;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.search-input {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.stats {
    color: var(--text-secondary);
    font-size: 0.9rem;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.session-info {
    font-size: 0.8rem;
    color: var(--accent-primary);
    opacity: 0.8;
}

.snippets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
    align-items: start;
}

.snippet-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.snippet-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.snippet-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

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

.action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
}

.action-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: scale(1.1);
}

.delete-btn:hover {
    color: var(--error-color);
}

.snippet-language {
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.snippet-date {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.snippet-code-container {
    position: relative;
    background: var(--bg-primary);
}

.snippet-code {
    padding: 1.5rem;
    padding-top: 3rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    background: var(--bg-primary);
    margin: 0;
    overflow-x: auto;
}

.code-copy-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border: 1px solid var(--border-color);
}

.code-copy-btn:hover {
    background: var(--bg-tertiary);
    color: var(--success-color);
    transform: scale(1.05);
}

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    color: var(--error-color);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.no-snippets {
    text-align: center;
    padding: 4rem 2rem;
}

.no-snippets-content h3 {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.no-snippets-content p {
    color: var(--text-secondary);
    opacity: 0.8;
}

.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    text-align: center;
    margin-top: auto;
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }
    
    .logo {
        font-size: 2rem;
    }
    
    .header-top {
        top: 0.5rem;
        right: 0.5rem;
    }
    
    .theme-toggle {
        width: 2rem;
        height: 2rem;
        font-size: 0.9rem;
    }
    
    .form-container {
        padding: 1.5rem;
    }
    
    .snippets-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .controls-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-group {
        max-width: none;
    }
    
    .stats {
        text-align: center;
        margin-top: 0.5rem;
        align-items: center;
    }
    
    .snippet-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }
    
    .snippet-info {
        flex: 1;
    }
    
    .snippet-actions {
        flex-shrink: 0;
    }
    
    .snippet-code {
        padding: 1rem;
        padding-top: 2.5rem;
        font-size: 0.85rem;
    }
    
    .code-copy-btn {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.4rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 1.5rem 0;
    }
    
    .main {
        padding: 1.5rem 0;
    }
    
    .form-container {
        padding: 1rem;
    }
    
    .snippet-code {
        font-size: 0.8rem;
        padding-top: 2.5rem;
    }
}

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

.snippet-card.new {
    animation: slideIn 0.3s ease-out;
}

.snippet-notes {
    padding: 1rem 1.5rem;
    font-size: 0.9rem;
    line-height: 1.7;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.snippet-notes h1, .snippet-notes h2, .snippet-notes h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.snippet-notes h1 { font-size: 1.2rem; }
.snippet-notes h2 { font-size: 1.1rem; }
.snippet-notes h3 { font-size: 1rem; }

.snippet-notes p {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.snippet-notes code {
    background-color: var(--bg-tertiary);
    padding: 0.2em 0.4em;
    font-size: 85%;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    color: var(--accent-light);
}

.snippet-notes pre {
    background-color: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1rem;
}

.snippet-notes pre code {
    background: none;
    padding: 0;
}

.snippet-notes ul, .snippet-notes ol {
    padding-left: 20px;
    margin-bottom: 1rem;
}

.snippet-notes li {
    margin-bottom: 0.3rem;
}

.snippet-notes blockquote {
    border-left: 3px solid var(--accent-primary);
    padding-left: 1rem;
    margin: 1rem 0;
    font-style: italic;
    color: var(--text-secondary);
}

.snippet-notes a {
    color: var(--accent-primary);
    text-decoration: none;
}

.snippet-notes a:hover {
    text-decoration: underline;
}

.tags-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.tags-container input {
    flex: 1;
}

.suggest-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

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

.suggest-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.snippet-tags {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    background: var(--accent-primary);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.ai-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.ai-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-width: 800px;
    max-height: 80vh;
    width: 90%;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

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

.ai-modal-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-weight: 600;
}

.ai-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.ai-modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.ai-modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.ai-modal-body::-webkit-scrollbar {
    width: 6px;
}

.ai-modal-body::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.ai-modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.ai-explanation {
    line-height: 1.6;
    color: var(--text-primary);
}

.ai-explanation h1, .ai-explanation h2, .ai-explanation h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--accent-primary);
}

.ai-explanation p {
    margin-bottom: 1rem;
}

.ai-explanation code {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    color: var(--accent-light);
}

.ai-explanation pre {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 1rem 0;
}

.ai-explanation ul, .ai-explanation ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.ai-loading i {
    margin-right: 0.5rem;
    animation: spin 1s linear infinite;
}

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