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

[data-theme="dark"] {
    --background: #1a1d21;
    --text: #e9ecef;
    --card-bg: #2d3748;
    --border: #4a5568;
    --highlight: rgba(246, 224, 94, 0.6);
    --group1: rgba(52, 152, 219, 0.6);
    --group2: rgba(46, 204, 113, 0.6);
    --group3: rgba(155, 89, 182, 0.6);
    --group4: rgba(241, 196, 15, 0.6);
    --group5: rgba(230, 126, 34, 0.6);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--background);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s, color 0.3s;
}

/* Main Container */
.regex-tester {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 1rem;
}

/* Header Section */
.regex-header {
    text-align: center;
    margin-bottom: 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.regex-header h1 {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 1rem;
    font-weight: 700;
}

.regex-header p {
    color: var(--gray);
    font-size: 1.1rem;
    max-width: 700px;
    margin: 0 auto 1.5rem;
}

.header-controls {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

/* Test Area */
.regex-test-area {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    margin-bottom: 2rem;
    transition: background 0.3s;
}

/* Input Groups */
.regex-input-group {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}

#save-btn {
    margin: auto auto 2px auto;
}

.regex-input-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: var(--text);
    font-size: 0.95rem;
}

.regex-input-group textarea,
.regex-input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.95rem;
    transition: all 0.2s;
    background: var(--card-bg);
    color: var(--text);
}

.regex-input-group textarea {
    min-height: 120px;
    resize: vertical;
}

.regex-input-group textarea:focus,
.regex-input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.regex-flags {
    position: absolute;
    right: 1.8rem;
    top: 4.2rem;
    display: flex;
    gap: 0.5rem;
}

.flag-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: var(--light-gray);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--dark);
}

/* Options Row */
.regex-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--light-gray);
    border-bottom: 1px solid var(--border);
}

.regex-option {
    display: flex;
    align-items: center;
}

.regex-option input {
    margin-right: 0.5rem;
}

.regex-option label {
    font-size: 0.9rem;
    color: var(--text);
}

/* Action Buttons */
.regex-actions {
    display: flex;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--light-gray);
}

.regex-btn {
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.regex-btn-primary:hover {
    background: var(--secondary);
    transform: translateY(-1px);
}

.regex-btn-secondary {
    background: #a7b6c5;
    color: var(--text);
}

.regex-btn-secondary:hover {
    background: var(--border);
}

/* Results Section */
.regex-results {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    margin-bottom: 2rem;
    transition: background 0.3s;
}

.regex-results-header {
    padding: 1rem 1.5rem;
    background: var(--primary);
    color: white;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.regex-results-body {
    padding: 1.5rem;
}

.regex-match {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    margin-bottom: 1.5rem;
}

.regex-match-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.regex-match-content {
    background: var(--light-gray);
    padding: 1rem;
    border-radius: 6px;
    border-left: 3px solid var(--primary);
    overflow-x: auto;
}

.regex-highlight {
    background: var(--highlight);
    padding: 0 2px;
    border-radius: 2px;
}

.group-1 {
    background-color: var(--group1);
}

.group-2 {
    background-color: var(--group2);
}

.group-3 {
    background-color: var(--group3);
}

.group-4 {
    background-color: var(--group4);
}

.group-5 {
    background-color: var(--group5);
}

.regex-no-matches {
    color: var(--gray);
    text-align: center;
    padding: 2rem;
}

/* Results Table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.results-table th,
.results-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.results-table th {
    background-color: var(--light-gray);
    font-weight: 600;
}

.results-table tr:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Replace Section */
.replace-section {
    margin-top: 1.5rem;
}

.replace-result {
    background: var(--light-gray);
    padding: 1rem;
    border-radius: 6px;
    margin-top: 0.5rem;
    white-space: pre-wrap;
}

/* Common Patterns */
.common-patterns {
    margin-top: 1rem;
}

.patterns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.pattern-btn {
    padding: 0.5rem;
    background: var(--light-gray);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

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

.pattern-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.pattern-regex {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Cheat Sheet */
.regex-cheatsheet {
    margin-top: 3rem;
}

.regex-cheatsheet h2 {
    font-size: 1.5rem;
    color: var(--text);
    margin-bottom: 1.5rem;
    text-align: center;
}

.cheatsheet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.cheatsheet-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: background 0.3s;
}

.cheatsheet-card h3 {
    color: var(--primary);
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.cheatsheet-item {
    margin-bottom: 1rem;
}

.cheatsheet-item code {
    background: var(--light-gray);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9rem;
    color: var(--warning);
}

.cheatsheet-item p {
    color: var(--text);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab.active {
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text);
}

/* Performance Indicator */
.performance {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Error Message */
.error-message {
    color: var(--danger);
    padding: 0.5rem;
    background: rgba(247, 37, 133, 0.1);
    border-radius: 4px;
    margin-top: 0.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .regex-header h1 {
        font-size: 2rem;
    }

    .regex-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .regex-btn {
        width: 100%;
    }

    .regex-flags {
        position: static;
        margin-top: 0.5rem;
    }
}

@media (max-width: 480px) {
    .regex-header h1 {
        font-size: 1.75rem;
    }

    .regex-input-group {
        padding: 1rem;
    }

    .regex-options {
        padding: 0.75rem 1rem;
    }

    .tabs {
        overflow-x: auto;
    }
}
