:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #111120;
    --bg-tertiary: #1a1a2e;
    --bg-glass: rgba(255, 255, 255, 0.03);
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(108, 99, 255, 0.3);
    --text-primary: #e8e8f0;
    --text-secondary: #8888a0;
    --text-muted: #555570;
    --accent: #6c63ff;
    --accent-glow: rgba(108, 99, 255, 0.2);
    --accent-2: #ff6b9d;
    --accent-3: #00d4aa;
    --accent-4: #f7b731;
    --gradient-1: linear-gradient(135deg, #6c63ff 0%, #a855f7 100%);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
    --font: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(108, 99, 255, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(255, 107, 157, 0.03) 0%, transparent 50%);
}

.app {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px 20px;
    position: relative;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 1.3rem;
    font-weight: 700;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.badge {
    font-size: 0.6rem;
    padding: 2px 8px;
    border-radius: 99px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-weight: 500;
}

.header-right {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-ghost {
    background: var(--bg-glass);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-primary {
    background: var(--gradient-1);
    color: #fff;
    border: none;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.72rem;
}

.btn-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-tertiary);
}

.btn-close {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.btn-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

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

.card-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Regex Input */
.input-row {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    transition: border-color var(--transition);
}

.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.regex-delimiter {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: 600;
}

.regex-flags {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-2);
    font-weight: 500;
    padding: 0 4px;
}

.regex-field {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    padding: 8px 4px;
    outline: none;
}

.regex-field::placeholder {
    color: var(--text-muted);
}

/* Flags */
.flags-group {
    display: flex;
    gap: 4px;
}

.flag-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.flag-toggle input {
    display: none;
}

.flag-toggle span {
    padding: 3px 7px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 4px;
    background: var(--bg-glass);
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.flag-toggle input:checked+span {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* English Output */
.english-output {
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.english-output .segment {
    display: inline;
}

.english-output .seg-literal {
    color: var(--accent-3);
    font-family: var(--font-mono);
    font-weight: 500;
    background: rgba(0, 212, 170, 0.1);
    padding: 1px 4px;
    border-radius: 3px;
}

.english-output .seg-quantifier {
    color: var(--accent-4);
}

.english-output .seg-anchor {
    color: var(--accent-2);
}

.english-output .seg-group {
    color: var(--accent);
}

.placeholder-text {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-style: italic;
}

/* Breakdown */
.breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.breakdown-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.breakdown-item:hover {
    background: var(--bg-glass);
}

.breakdown-token {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    background: rgba(108, 99, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    min-width: 40px;
    text-align: center;
}

.breakdown-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Test */
textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    resize: vertical;
    transition: border-color var(--transition);
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea::placeholder {
    color: var(--text-muted);
}

.match-count {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-3);
}

.match-results {
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.8;
    word-break: break-all;
}

.match-results .match-highlight {
    background: rgba(108, 99, 255, 0.25);
    color: var(--accent);
    padding: 1px 2px;
    border-radius: 2px;
    border-bottom: 2px solid var(--accent);
}

/* Pattern Library */
.pattern-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.pattern-item {
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.pattern-item:hover {
    border-color: var(--border-hover);
    background: var(--bg-glass);
    transform: translateY(-1px);
}

.pattern-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.pattern-regex {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--accent);
    word-break: break-all;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 360px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 500;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.25s ease;
}

.sidebar.hidden {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.cheat-section {
    margin-bottom: 20px;
}

.cheat-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.cheat-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.cheat-token {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 500;
}

.cheat-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-align: right;
}

/* Favorites */
.fav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    cursor: pointer;
    transition: all var(--transition);
}

.fav-item:hover {
    background: var(--bg-glass);
}

.fav-info {
    flex: 1;
}

.fav-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.fav-regex {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--accent);
    margin-top: 2px;
}

.fav-remove {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 0, 0, 0.1);
    border-radius: 4px;
    color: #ff4757;
    cursor: pointer;
    font-size: 0.6rem;
}

/* Responsive */
@media (max-width: 768px) {
    .app {
        padding: 16px 12px;
    }

    .pattern-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: 100%;
    }
}