:root {
    --primary: #84CC16;
    --primary-glow: rgba(132, 204, 22, 0.15);
    --secondary: #A3E635;
    --accent: #8B5CF6;
    --accent-glow: rgba(139, 92, 246, 0.15);
    --bg: #0A1A0A;
    --bg-card: #0F2510;
    --bg-input: #0C1E0C;
    --border: rgba(163, 230, 53, 0.1);
    --border-hover: rgba(163, 230, 53, 0.25);
    --text: #E2E8F0;
    --text-muted: #94A3B8;
    --text-dim: #64748B;
    --success: #10B981;
    --error: #F87171;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --glass: rgba(15, 37, 16, 0.7);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    background-image: radial-gradient(ellipse at 20% 0%, rgba(132, 204, 22, 0.06) 0%, transparent 60%), radial-gradient(ellipse at 80% 100%, rgba(139, 92, 246, 0.04) 0%, transparent 60%)
}

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border)
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: .75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between
}

.logo-group {
    display: flex;
    align-items: center;
    gap: .75rem
}

.logo-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    flex-shrink: 0
}

.logo-title {
    font-size: 1.125rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text
}

.logo-subtitle {
    font-size: .75rem;
    color: var(--text-dim)
}

.header-actions {
    display: flex;
    align-items: center;
    gap: .75rem
}

.template-select {
    padding: .4rem .75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: var(--font);
    font-size: .8125rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .5rem center;
    padding-right: 1.75rem
}

.template-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow)
}

.template-select option {
    background: var(--bg-card);
    color: var(--text)
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font);
    font-size: .8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border)
}

.btn-ghost:hover {
    background: var(--primary-glow);
    color: var(--primary);
    border-color: rgba(132, 204, 22, 0.3)
}

.btn-accent {
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid rgba(139, 92, 246, 0.25)
}

.btn-accent:hover {
    background: rgba(139, 92, 246, 0.2)
}

.btn-sm {
    padding: .325rem .625rem;
    font-size: .75rem
}

.main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: .75rem
}

.input-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem .75rem
}

.input-prefix,
.input-suffix {
    font-family: var(--mono);
    font-size: 1.125rem;
    color: var(--text-dim);
    font-weight: 600
}

.regex-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--secondary);
    font-family: var(--mono);
    font-size: .9375rem;
    outline: none;
    padding: .25rem
}

.regex-input::placeholder {
    color: var(--text-dim)
}

.flags-group {
    display: flex;
    gap: .25rem
}

.flag-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center
}

.flag-btn:hover {
    border-color: var(--border-hover)
}

.flag-btn.active {
    background: var(--primary-glow);
    color: var(--primary);
    border-color: rgba(132, 204, 22, 0.3)
}

.explanation {
    padding: .75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .8125rem;
    color: var(--text-muted);
    min-height: 2.5rem;
    line-height: 1.5
}

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

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden
}

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

.panel-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9375rem;
    font-weight: 600
}

.panel-title svg {
    color: var(--primary)
}

.panel-body {
    padding: 1.25rem
}

.diagram-panel {
    min-height: 200px
}

.diagram-controls {
    display: flex;
    gap: .25rem
}

.diagram-viewport {
    overflow: auto;
    padding: 1.5rem;
    min-height: 180px;
    position: relative
}

.diagram-viewport::-webkit-scrollbar {
    height: 6px;
    width: 6px
}

.diagram-viewport::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px
}

.diagram-canvas {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: min-content;
    transform-origin: left center;
    transition: transform .2s ease
}

.rr-node {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .375rem .75rem;
    border-radius: var(--radius-xs);
    font-family: var(--mono);
    font-size: .75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    white-space: nowrap;
    border: 2px solid transparent
}

.rr-node:hover {
    transform: scale(1.05);
    z-index: 10
}

.rr-node.active {
    border-color: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow)
}

.rr-literal {
    background: rgba(132, 204, 22, 0.12);
    color: var(--primary);
    border-color: rgba(132, 204, 22, 0.3)
}

.rr-class {
    background: rgba(59, 130, 246, 0.12);
    color: #60A5FA;
    border-color: rgba(59, 130, 246, 0.3)
}

.rr-group {
    background: rgba(139, 92, 246, 0.12);
    color: var(--accent);
    border-color: rgba(139, 92, 246, 0.3)
}

.rr-quantifier {
    background: rgba(245, 158, 11, 0.12);
    color: #F59E0B;
    border-color: rgba(245, 158, 11, 0.3)
}

.rr-anchor {
    background: rgba(236, 72, 153, 0.12);
    color: #F472B6;
    border-color: rgba(236, 72, 153, 0.3)
}

.rr-alt {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.3)
}

.rr-connector {
    width: 24px;
    height: 2px;
    background: var(--border);
    flex-shrink: 0;
    position: relative
}

.rr-connector::before {
    content: '';
    position: absolute;
    right: -3px;
    top: -3px;
    width: 0;
    height: 0;
    border-left: 6px solid var(--border);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent
}

.rr-group-wrap {
    display: flex;
    align-items: center;
    gap: 0;
    padding: .25rem .375rem;
    border: 1px dashed rgba(139, 92, 246, 0.3);
    border-radius: var(--radius);
    position: relative
}

.rr-group-label {
    position: absolute;
    top: -10px;
    left: 8px;
    font-size: .625rem;
    color: var(--accent);
    background: var(--bg-card);
    padding: 0 .25rem;
    font-family: var(--mono)
}

.rr-alt-wrap {
    display: flex;
    flex-direction: column;
    gap: .375rem;
    padding: .375rem;
    border: 1px dashed rgba(16, 185, 129, 0.3);
    border-radius: var(--radius)
}

.rr-alt-branch {
    display: flex;
    align-items: center;
    gap: 0
}

.node-info {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border);
    animation: slideUp .2s ease-out
}

.node-info[hidden] {
    display: none
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(4px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

.node-info-title {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--primary);
    font-family: var(--mono)
}

.node-info-desc {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .25rem
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem
}

.test-input {
    width: 100%;
    padding: .75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: var(--mono);
    font-size: .8125rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    margin-bottom: .75rem
}

.test-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow)
}

.match-count {
    font-size: .75rem;
    color: var(--text-dim);
    font-family: var(--mono)
}

.test-results {
    display: flex;
    flex-direction: column;
    gap: .375rem
}

.test-result {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    border-radius: var(--radius-xs);
    font-family: var(--mono);
    font-size: .75rem
}

.test-result--match {
    background: rgba(132, 204, 22, 0.08);
    border: 1px solid rgba(132, 204, 22, 0.2)
}

.test-result--no-match {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.15)
}

.test-result-icon {
    flex-shrink: 0
}

.test-result-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

.test-result-text mark {
    background: rgba(132, 204, 22, 0.3);
    color: var(--secondary);
    border-radius: 2px;
    padding: 0 2px
}

.groups-list {
    display: flex;
    flex-direction: column;
    gap: .5rem
}

.group-item {
    padding: .625rem .75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    gap: .75rem
}

.group-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-glow);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    font-family: var(--mono);
    flex-shrink: 0
}

.group-info {
    flex: 1
}

.group-pattern {
    font-family: var(--mono);
    font-size: .8125rem;
    color: var(--secondary)
}

.group-desc {
    font-size: .6875rem;
    color: var(--text-dim);
    margin-top: .15rem
}

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: .5rem
}

.toast {
    padding: .75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: .8125rem;
    animation: toastIn .3s ease-out
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px)
    }

    to {
        opacity: 1;
        transform: translateX(0)
    }
}

@media(max-width:1024px) {
    .content-grid {
        grid-template-columns: 1fr
    }
}

@media(max-width:768px) {
    .main {
        padding: 1rem
    }

    .input-row {
        flex-wrap: wrap
    }

    .flags-group {
        width: 100%;
        justify-content: flex-start
    }
}

@media(max-width:480px) {
    .logo-subtitle {
        display: none
    }
}