:root {
    --bg-dark: #0f111a;
    --bg-panel: #1a1d27;
    --bg-card: #232736;
    --bg-hover: #2f354a;
    --border-color: #2f354a;

    --text-main: #e2e8f0;
    --text-muted: #94a3b8;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --highlight: #8b5cf6;
    /* purple for matching elements */

    --font-sans: 'Plus Jakarta Sans', -apple-system, sans-serif;
    --font-mono: 'Fira Code', monospace;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Utilities */
.text-primary {
    color: var(--primary);
}

.text-success {
    color: var(--success);
}

.text-warning {
    color: var(--warning);
}

.text-danger {
    color: var(--danger);
}

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

.hidden {
    display: none !important;
}

/* Navbar */
.navbar {
    height: 60px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

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

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

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

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

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Main Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panels Generic */
.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-panel);
    position: sticky;
    top: 0;
    z-index: 10;
}

.panel-header h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Left Panel: Glossary */
.glossary-panel {
    width: 280px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.glossary-category {
    padding: 0.75rem 1.5rem 0.25rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.glossary-item {
    padding: 0.5rem 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

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

.glossary-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.token-symbol {
    color: var(--primary);
    font-weight: bold;
    width: 1.5rem;
    display: inline-block;
}

/* Center Panel: Sandbox */
.sandbox-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
}

.editor-header {
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    background: var(--bg-dark);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--primary);
    flex: 1;
    max-width: 800px;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.input-wrapper .prompt {
    color: var(--text-muted);
}

.selector-input {
    background: transparent;
    border: none;
    color: white;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    flex: 1;
    outline: none;
    width: 100%;
}

.selector-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

.match-count {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(139, 92, 246, 0.5);
}

.quiz-prompt {
    background: rgba(245, 158, 11, 0.1);
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}

.blink-indicator {
    color: var(--danger);
    font-weight: bold;
    animation: textBlink 1s infinite alternate;
}

@keyframes textBlink {
    0% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
        text-shadow: 0 0 8px var(--danger);
    }
}

/* DOM Visualizer */
.dom-container {
    flex: 1;
    padding: 2rem;
    overflow: auto;
}

.sandbox-root {
    max-width: 900px;
    margin: 0 auto;
}

/* The magic blocks */
.sb-node {
    border: 1px dashed var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    padding: 1rem 0.5rem 0.5rem 1.5rem;
    margin: 0.5rem 0;
    border-radius: 6px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--font-sans);
    color: var(--text-muted);
}

.sb-node::before {
    content: '<' attr(data-tag) '>';
    position: absolute;
    top: -8px;
    left: 8px;
    background: var(--bg-dark);
    padding: 0 4px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--primary);
    font-weight: 700;
    opacity: 0.7;
}

/* Identify ID and Classes in tags */
.sb-node[id]::before {
    content: '<' attr(data-tag) ' id="' attr(id) '">';
    color: var(--warning);
}

.sb-node[class*=" "]::before {
    /* Hacky way to catch elements with actual classes alongside sb-node */
    color: var(--success);
}

/* Active Highlight state for selected elements! */
.sb-node.is-match {
    background: rgba(139, 92, 246, 0.15);
    border-color: var(--highlight);
    border-style: solid;
    color: white;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
    transform: scale(1.01);
    z-index: 5;
}

.sb-node.is-match>*:not(.is-match) {
    opacity: 0.6;
    /* Dim non-matching children slightly to emphasize the match */
}

.sb-node.quiz-target {
    animation: quizTargetBlink 1s infinite alternate;
}

@keyframes quizTargetBlink {
    0% {
        box-shadow: inset 0 0 0 2px var(--danger);
    }

    100% {
        box-shadow: inset 0 0 15px var(--danger);
    }
}


/* Right Panel: Explainer */
.explainer-panel {
    width: 350px;
    border-left: 1px solid var(--border-color);
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
}

.explainer-content {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    gap: 1rem;
    color: var(--text-muted);
}

/* Dynamically injected content */
.explainer-title {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.explainer-desc {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    color: var(--text-main);
}

.explainer-code {
    background: var(--bg-dark);
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.explainer-code-target {
    color: var(--highlight);
    font-weight: bold;
}

.explainer-tip {
    background: rgba(59, 130, 246, 0.1);
    border-left: 3px solid var(--primary);
    padding: 1rem;
    border-radius: 0 6px 6px 0;
    font-size: 0.9rem;
    line-height: 1.5;
}