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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.controls {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.language-selector label {
    font-weight: 600;
    color: #555;
}

.language-selector select {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.3s;
}

.language-selector select:focus {
    outline: none;
    border-color: #667eea;
}

.snippet-controls {
    display: flex;
    gap: 10px;
    flex: 1;
    flex-wrap: wrap;
}

#snippetTitle {
    flex: 1;
    min-width: 200px;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

#snippetTitle:focus {
    outline: none;
    border-color: #667eea;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 5px;
}

#saveBtn {
    background: #4CAF50;
    color: white;
}

#saveBtn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

#clearBtn {
    background: #f44336;
    color: white;
}

#clearBtn:hover {
    background: #d32f2f;
    transform: translateY(-2px);
}

#copyBtn {
    background: #2196F3;
    color: white;
}

#copyBtn:hover {
    background: #1976D2;
    transform: translateY(-2px);
}

#shareBtn {
    background: #FF5722;
    color: white;
}

#shareBtn:hover {
    background: #E64A19;
    transform: translateY(-2px);
}

.online-controls {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.online-controls h3 {
    margin-bottom: 15px;
    color: #333;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

.online-controls-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

#searchInput {
    flex: 1;
    min-width: 200px;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

#searchInput:focus {
    outline: none;
    border-color: #667eea;
}

#languageFilter {
    padding: 10px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.3s;
}

#languageFilter:focus {
    outline: none;
    border-color: #667eea;
}

#searchBtn {
    background: #9C27B0;
    color: white;
}

#searchBtn:hover {
    background: #7B1FA2;
    transform: translateY(-2px);
}

#loadOnlineBtn {
    background: #00BCD4;
    color: white;
}

#loadOnlineBtn:hover {
    background: #0097A7;
    transform: translateY(-2px);
}

.loading-indicator {
    display: none;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 15px;
    color: #666;
    font-size: 14px;
}

.loading-indicator.show {
    display: flex;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.snippets-container {
    display: grid;
    gap: 30px;
    grid-template-columns: 1fr 1fr;
}

.online-snippets,
.saved-snippets {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.online-snippets h3,
.saved-snippets h3 {
    margin-bottom: 20px;
    color: #333;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

.online-snippet {
    border-left: 4px solid #FF5722;
}

.local-snippet {
    border-left: 4px solid #4CAF50;
}

.snippet-stats {
    font-size: 12px;
    color: #666;
    margin-bottom: 10px;
}

.toast.info {
    background: #2196F3;
}

/* 響應式設計更新 */
@media (max-width: 768px) {
    .snippets-container {
        grid-template-columns: 1fr;
    }
    
    .online-controls-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    #searchInput {
        min-width: auto;
    }
}

.editor-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    overflow: hidden;
    position: relative;
}

#codeEditor {
    width: 100%;
    height: 400px;
    padding: 20px;
    border: none;
    resize: vertical;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    background: #2d3748;
    color: #e2e8f0;
    outline: none;
}

#codePreview {
    display: none;
    margin: 0;
    max-height: 400px;
    overflow: auto;
}

#codePreview code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.saved-snippets {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.saved-snippets h3 {
    margin-bottom: 20px;
    color: #333;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

.snippets-list {
    display: grid;
    gap: 15px;
}

.snippet-item {
    border: 2px solid #eee;
    border-radius: 8px;
    padding: 15px;
    transition: all 0.3s;
    cursor: pointer;
}

.snippet-item:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.1);
}

.snippet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.snippet-title {
    font-weight: 600;
    color: #333;
    font-size: 16px;
}

.snippet-language {
    background: #667eea;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.snippet-date {
    font-size: 12px;
    color: #666;
    margin-bottom: 10px;
}

.snippet-preview {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    color: #333;
    white-space: pre-wrap;
    max-height: 100px;
    overflow: hidden;
    position: relative;
}

.snippet-preview::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(transparent, #f8f9fa);
}

.snippet-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.snippet-actions button {
    padding: 6px 12px;
    font-size: 12px;
}

.load-btn {
    background: #FF9800;
    color: white;
}

.load-btn:hover {
    background: #F57C00;
}

.delete-btn {
    background: #f44336;
    color: white;
}

.delete-btn:hover {
    background: #d32f2f;
}

.copy-snippet-btn {
    background: #2196F3;
    color: white;
}

.copy-snippet-btn:hover {
    background: #1976D2;
}

footer {
    text-align: center;
    margin-top: 30px;
    color: white;
    opacity: 0.8;
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 15px 20px;
    border-radius: 6px;
    transform: translateX(400px);
    transition: transform 0.3s;
    z-index: 1000;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    background: #4CAF50;
}

.toast.error {
    background: #f44336;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #666;
}

.empty-state h4 {
    margin-bottom: 10px;
    font-size: 18px;
}

.empty-state p {
    margin-bottom: 20px;
}

.preview-mode .editor-container {
    height: auto;
}

.preview-mode #codeEditor {
    display: none;
}

.preview-mode #codePreview {
    display: block;
    padding: 20px;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .snippet-controls {
        flex-direction: column;
    }
    
    #snippetTitle {
        min-width: auto;
    }
    
    .snippet-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .snippet-actions {
        flex-wrap: wrap;
    }
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}
