:root {
    --bg-main: #111;
    --bg-panel: #191919;
    --bg-darker: #1a1a1a;
    --accent: #5865f2;
    --text: #dbdee1;
    --text-muted: #949ba4;
    --border: #3f4147;

    /* Regex Group Colors */
    --hl-1: #5865f2;
    --hl-2: #ed4245;
    --hl-3: #57f287;
    --hl-4: #faa61a;
    --hl-5: #eb459e;

    --font-mono: 'Fira Code', monospace;
    --font-ui: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--text);
    font-family: var(--font-ui);
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    height: 48px;
    background: var(--bg-darker);
    border-bottom: 1px solid #111;
    display: flex;
    align-items: center;
    padding: 0 16px;
    justify-content: space-between;
}

.brand {
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
}

.brand .accent {
    color: var(--accent);
}

/* Main Layout */
.app-container {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

/* Regex Input Bar */
.regex-section {
    background: var(--bg-panel);
    padding: 8px 12px;
    border-radius: 6px;
}

.header-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
}

.error-msg {
    color: #fa777c;
    font-weight: 500;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-darker);
    border-radius: 4px;
    border: 1px solid var(--border);
    transition: 0.2s;
    padding: 6px;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.delimiter {
    font-family: var(--font-mono);
    color: #666;
    font-size: 18px;
    margin: 0 6px;
    user-select: none;
}

.input-container {
    position: relative;
    flex: 1;
    height: 24px;
}

.regex-input,
.input-overlay {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    padding: 0;
    font-family: var(--font-mono);
    font-size: 16px;
    position: absolute;
    top: 0;
    left: 0;
}

.regex-input {
    z-index: 2;
    color: #f0f0f0;
    outline: none;
}

.flags-input {
    width: 50px;
    background: transparent;
    border: none;
    color: #e0b400;
    font-family: var(--font-mono);
    font-size: 15px;
    outline: none;
    font-weight: 700;
}

/* Workspace Grid */
.workspace {
    display: grid;
    grid-template-columns: 240px 1fr 300px;
    gap: 8px;
    flex: 1;
    overflow: hidden;
}

/* Panels */
.panel {
    background: var(--bg-panel);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    background: #1d1d1d;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--bg-main);
}

.actions button {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    transition: 0.2s;
}

.actions button:hover {
    color: #fff;
}

.custom-scroll::-webkit-scrollbar {
    width: 0;
}

.custom-scroll {
    overflow: auto;
}

/* Left Reference */
.search-bar {
    padding: 8px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid #000;
}

.search-bar i {
    color: #666;
    font-size: 12px;
    margin-top: 3px;
}

.search-bar input {
    background: transparent;
    border: none;
    color: #ddd;
    outline: none;
    font-size: 12px;
    width: 100%;
}

.ref-category-header {
    font-size: 10px;
    color: var(--accent);
    font-weight: 800;
    text-transform: uppercase;
    padding: 8px 12px 4px;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

.ref-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid #333;
}

.ref-item:hover {
    background: #333;
}

.ref-code {
    font-family: var(--font-mono);
    color: #a5b3ff;
    background: #3b3d45;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
}

/* Center Editor */
.editor-container {
    display: flex;
    flex: 1;
    background: var(--bg-darker);
    position: relative;
    overflow: hidden;
}

.gutter {
    width: 35px;
    background: #1e1f22;
    border-right: 1px solid #333;
    color: #555;
    text-align: right;
    padding: 10px 6px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 22px;
    user-select: none;
}

.editor-wrapper {
    flex: 1;
    position: relative;
    overflow: auto;
}

.editor-textarea,
.editor-overlay {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 100%;
    min-height: 100%;
    padding: 10px;
    box-sizing: border-box;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 22px;
    white-space: pre-wrap;
    word-wrap: break-word;
    border: none;
}

.editor-textarea {
    z-index: 5;
    color: transparent;
    background: transparent;
    caret-color: white;
    outline: none;
    resize: none;
}

.editor-overlay {
    z-index: 1;
    pointer-events: none;
    color: #b9bbbe;
}

/* Highlight Classes */
.hl-match {
    background: rgba(88, 101, 242, 0.25);
    border-bottom: 2px solid rgba(88, 101, 242, 0.7);
    border-radius: 2px;
}

.hl-1 {
    border-color: var(--hl-1);
    background: rgba(88, 101, 242, 0.2);
}

.hl-2 {
    border-color: var(--hl-2);
    background: rgba(237, 66, 69, 0.2);
}

.hl-3 {
    border-color: var(--hl-3);
    background: rgba(87, 242, 135, 0.2);
}

.hl-4 {
    border-color: var(--hl-4);
    background: rgba(250, 166, 26, 0.2);
}

/* Right Results */
.tabs {
    display: flex;
    background: #1e1f22;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 8px;
    font-size: 11px;
    font-weight: 700;
    color: #777;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: #fff;
    border-bottom-color: var(--accent);
    background: var(--bg-panel);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.tab-content.active {
    display: block;
}

.meta-info {
    font-size: 10px;
    text-align: center;
    color: #666;
    margin-bottom: 10px;
}

/* Match Cards */
.match-card {
    background: #1e1f22;
    border: 1px solid #111;
    border-radius: 4px;
    margin-bottom: 8px;
    cursor: pointer;
}

.match-header {
    background: #26272d;
    padding: 5px 8px;
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #888;
    font-weight: 700;
}

.match-body {
    padding: 8px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: #ddd;
    word-break: break-all;
}

.match-groups {
    background: #18191c;
    padding: 6px;
    border-top: 1px solid #2b2d31;
}

.grp-row {
    display: grid;
    grid-template-columns: 25px 1fr;
    margin-bottom: 3px;
    font-size: 12px;
}

.grp-id {
    color: #555;
    font-family: var(--font-mono);
}

.grp-val {
    color: var(--hl-3);
    font-family: var(--font-mono);
}

/* Explanation Tree */
.tree-node {
    margin-bottom: 4px;
    padding: 6px;
    border-radius: 4px;
    background: #252628;
    border-left: 3px solid #444;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.tree-node.structure {
    border-left-color: var(--accent);
    background: #2c2e33;
}

.tree-node.literal {
    border-left-color: #666;
}

.tree-token {
    font-family: var(--font-mono);
    background: #18191c;
    color: #7289da;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    min-width: 24px;
    text-align: center;
    height: 20px;
}

.tree-desc strong {
    display: block;
    font-size: 12px;
    color: #ddd;
}

.tree-desc p {
    margin: 2px 0 0;
    font-size: 11px;
    color: #949ba4;
    line-height: 1.3;
}

.empty-state {
    text-align: center;
    margin-top: 30px;
    font-style: italic;
    color: #555;
    font-size: 13px;
}

/* --- DEBUGGER STYLES --- */
.debug-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 8px;
    border-bottom: 1px solid #333;
    margin-bottom: 8px;
}

.debug-controls button {
    background: #2b2d31;
    border: 1px solid #111;
    color: #ddd;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
}

.debug-controls button:hover {
    background: #3e4046;
}

.step-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

#step-counter {
    font-family: var(--font-mono);
    font-size: 12px;
    color: #888;
    min-width: 60px;
    text-align: center;
}

.timeline-slider-container {
    padding: 0 0 8px;
}

#step-slider {
    width: 100%;
    accent-color: var(--accent);
    height: 4px;
}

.debug-status {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 8px;
    font-family: var(--font-mono);
    min-height: 16px;
}

.debug-timeline {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.debug-step-item {
    padding: 4px 8px;
    font-size: 11px;
    background: #1e1f22;
    border-radius: 4px;
    border-left: 3px solid transparent;
    cursor: pointer;
    font-family: var(--font-ui);
    display: flex;
    justify-content: space-between;
}

.debug-step-item:hover {
    background: #282a2e;
}

.debug-step-item.active {
    background: #32343a;
    border-left-color: #fff;
}

.debug-step-item .step-id {
    color: #666;
    margin-right: 8px;
    font-family: var(--font-mono);
}

/* Step Types */
.step-match {
    border-left-color: var(--hl-3);
}

.step-fail {
    border-left-color: var(--hl-2);
}

.step-backtrack {
    border-left-color: var(--hl-4);
}

.step-finish {
    border-left-color: var(--accent);
}

.step-group_in {
    border-left-color: #a5b3ff;
}

.step-group_out {
    border-left-color: #a5b3ff;
}

/* In-Editor Highlight for Debugger */
.debug-cursor {
    position: absolute;
    width: 2px;
    background-color: #fff;
    animation: blink 1s infinite;
    z-index: 10;
}

.debug-highlight {
    background-color: rgba(255, 255, 255, 0.2);
    border-bottom: 2px solid #fff;
    position: absolute;
    /* or inline depending on implementation */
    z-index: 9;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}