:root {
    --bg-color: #050505;
    --panel-bg: #0f0f0f;
    --panel-border: #222;
    --text-primary: #ededed;
    --text-secondary: #888;
    --accent: #e2e8f0;
    --accent-hover: #fff;
    --accent-bg: #1a1a1a;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --feature-accent: #10b981;
    /* Emerald */
    --feature-accent-hover: #34d399;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
    scroll-behavior: smooth;
    padding: 2rem 0 6rem 0;
}

.container {
    width: 95%;
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -1.5px;
    color: #fff;
    margin-bottom: 0.5rem;
}

.badge {
    font-size: 1rem;
    vertical-align: super;
    background: #fff;
    color: #000;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
}

header p {
    color: var(--text-secondary);
    font-size: 1.15rem;
}

/* Theory Section */
.theory-section {
    background: url('data:image/svg+xml;utf8,<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M 40 0 L 0 0 0 40" fill="none" stroke="%23181818" stroke-width="1"/></pattern></defs><rect width="100%" height="100%" fill="url(%23grid)" /></svg>');
    background-color: #080808;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 3rem;
    margin-bottom: 4rem;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.8);
}

.theory-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.theory-header h2 {
    font-size: 2.2rem;
    color: #fff;
    margin-bottom: 1rem;
}

.theory-header p {
    font-size: 1.1rem;
    color: #aaa;
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.5;
}

.theory-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

.theory-card {
    background: #0d0d0d;
    border: 1px solid #222;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s ease;
}

.theory-card:hover {
    transform: translateY(-5px);
    border-color: #444;
}

.theory-icon {
    font-size: 1.5rem;
    font-weight: bold;
    color: #fff;
    background: #1a1a1a;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid #333;
    margin-bottom: 1.5rem;
}

.theory-card h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: #fff;
}

.theory-card p,
.theory-card strong {
    color: #999;
    font-size: 0.95rem;
    line-height: 1.6;
    font-weight: 400;
}

.theory-card strong {
    color: #ccc;
    font-weight: 600;
}

.highlight {
    color: var(--success);
    font-weight: 600;
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.theory-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 3rem;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

/* Definition Grid */
.definition-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 4rem;
}

.definition-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.definition-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.definition-card h4 {
    color: #fff;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.definition-card .symbol {
    font-family: 'Fira Code', monospace;
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.definition-card p {
    color: #888;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Apps Section */
.apps-section {
    margin-top: 4rem;
    padding-top: 3rem;
    border-top: 1px solid #222;
}

.apps-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

.app-item h4 {
    color: #fff;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.app-item p {
    color: #777;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* New Theory Enhancements */
.theory-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, #222, transparent);
    margin: 4rem 0;
}

.pro-tip {
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 1.2rem;
    border-radius: 8px;
    margin: 2rem 0;
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.pro-tip .icon {
    font-size: 1.2rem;
    color: var(--success);
}

.pro-tip p {
    color: #888;
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0;
}

.before-after-table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    background: #0a0a0a;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #222;
}

.before-after-table th,
.before-after-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid #111;
}

.before-after-table th {
    background: #111;
    color: #888;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.before-after-table td {
    font-family: 'Fira Code', monospace;
    font-size: 0.95rem;
    color: #ccc;
}

.before-after-table code {
    color: var(--success);
}

.concept-btn {
    background: transparent;
    border: 1px solid #333;
    color: #888;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 10px;
}

.concept-btn:hover {
    border-color: var(--success);
    color: #fff;
}

.concept-badge {
    background: #1a1a1a;
    border: 1px solid #333;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #ffd700;
    /* Gold/Yellow for badges */
}

.formal-math {
    background: rgba(0, 0, 0, 0.4);
    border-left: 3px solid #666;
    padding: 10px 15px;
    margin: 15px 0;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    border-radius: 4px;
    line-height: 1.6;
}

.formal-math .math-operator {
    color: #34d399;
    font-weight: bold;
}

.formal-math .math-set {
    color: #facc15;
}

.formal-math .math-var {
    color: #60a5fa;
}

.formal-math .math-label {
    color: #888;
    font-size: 0.75rem;
    text-transform: uppercase;
    display: block;
    margin-bottom: 6px;
    letter-spacing: 1px;
    font-family: 'Outfit', sans-serif;
}

/* Panels */
.panel {
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 2.5rem;
    margin-bottom: 3rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #fff;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.5;
}

/* Input Area Grid */
.input-methods-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.input-pane {
    background: #0a0a0a;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.input-pane h3 {
    margin-bottom: 1rem;
    font-weight: 500;
    color: #ddd;
    border-bottom: 1px solid #222;
    padding-bottom: 0.5rem;
}

textarea {
    width: 100%;
    min-height: 250px;
    background: #000;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 1.5rem;
    color: #fff;
    font-family: 'Fira Code', monospace;
    font-size: 1.1rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: #666;
}

.mt-2 {
    margin-top: 1rem;
}

.w-full {
    width: 100%;
}

/* Rule Builder */
.builder-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.builder-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1.5rem;
}

.builder-input {
    background: #000;
    border: 1px solid #333;
    color: #fff;
    padding: 12px;
    border-radius: 6px;
    font-family: 'Fira Code', monospace;
    font-size: 1.1rem;
}

.builder-input:focus {
    outline: none;
    border-color: #666;
}

.lhs-input {
    width: 80px;
    text-align: center;
}

.rhs-input {
    flex: 1;
}

.arrow-icon {
    color: #666;
    font-size: 1.2rem;
    font-weight: bold;
}

/* Select Base Style */
select.builder-input {
    border-right: 12px solid transparent;
    cursor: pointer;
    color: #ccc;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.1rem;
}

.btn-primary {
    background: #000;
    color: #fff;
    border: 1px solid #fff;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.btn-primary:hover {
    background: #fff;
    color: #000;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 255, 255, 0.1);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: #888;
    border: 1px solid #333;
}

.btn-secondary:hover {
    background: #1a1a1a;
    color: #fff;
    border-color: #555;
    transform: translateY(-1px);
}

.btn-feature {
    background: transparent;
    color: var(--feature-accent);
    border-color: var(--feature-accent);
}

.btn-feature:hover {
    background: var(--feature-accent);
    color: #000;
    /* Contrast with green */
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.btn-feature-solid {
    background: var(--feature-accent);
    color: #000;
    border-color: var(--feature-accent);
}

.btn-feature-solid:hover {
    background: var(--feature-accent-hover);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

.panel-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--panel-border);
    padding-top: 1.5rem;
}

.center-actions {
    justify-content: center;
}

/* Action Cards for Main Control */
.action-card {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid #1a1a1a;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.action-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: #333;
    transform: translateY(-5px);
}

.action-description {
    color: #888;
    font-size: 0.95rem;
    text-align: center;
    max-width: 250px;
    line-height: 1.4;
    font-weight: 400;
}

/* Pipeline Results Visibility */
.hidden {
    display: none !important;
}

.pipeline-header {
    text-align: center;
    margin: 5rem 0 3rem 0;
}

.pipeline-header h2 {
    font-size: 2.5rem;
    border-bottom: 2px solid #333;
    display: inline-block;
    padding-bottom: 1rem;
    color: #fff;
}

.pipeline-header p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* Dashboards and Layout Containers */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    min-height: 500px;
    align-items: stretch;
}

.dashboard-grid.full-width {
    grid-template-columns: 1fr 1.5fr;
}

.logs-pane,
.visuals-pane {
    background: #0a0a0a;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.logs-pane {
    position: relative;
}

.logs-pane h3,
.visuals-pane h3,
.graph-wrapper h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: #bbb;
    border-bottom: 1px solid #222;
    padding-bottom: 0.5rem;
    font-weight: 500;
}

/* Before & After State Containers */
.state-container {
    display: flex;
    gap: 1rem;
    flex: 1;
    margin-top: 1rem;
    min-height: 250px;
}

.grammar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #000;
    border-radius: 6px;
    border: 1px solid #222;
}

.grammar-col h4 {
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid #222;
    color: #888;
    font-size: 0.95rem;
    margin-bottom: 0;
    background: #0a0a0a;
}

.logs-content {
    position: absolute;
    top: 4.5rem;
    bottom: 1.5rem;
    left: 1.5rem;
    right: 1.5rem;
    overflow-y: auto;
    font-size: 0.95rem;
    padding-right: 5px;
}

.grammar-display {
    padding: 0.75rem;
    flex: 1;
    overflow-y: auto;
    font-family: 'Fira Code', monospace;
    max-height: 400px;
}

/* Graph container */
.graph-wrapper {
    position: relative;
    margin-bottom: 1rem;
    background: #000;
    border: 1px solid #222;
    border-radius: 6px;
    padding: 10px;
}

.graph-wrapper h3 {
    border-bottom: none;
    margin-bottom: 0.5rem;
    padding-bottom: 0;
}

.network-canvas {
    width: 100%;
    height: 300px;
    background: #050505;
    border-radius: 4px;
    position: relative;
    cursor: grab;
}

.network-canvas:active {
    cursor: grabbing;
}

.btn-reset-graph {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-reset-graph:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-reset-graph:active {
    transform: translateY(0);
}

.btn-reset-graph::before {
    content: '↺';
    font-size: 1.1rem;
    line-height: 1;
}

/* Stage Stats */
.stage-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    padding: 24px;
    border-radius: 12px;
    border: 1px dashed #444;
}

.stat-pill {
    background: #0d0d0d;
    border: 1px solid #333;
    padding: 14px 28px;
    border-radius: 8px;
    font-size: 1.15rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    transition: transform 0.2s;
}

.stat-pill:hover {
    transform: translateY(-3px);
    border-color: #666;
}

.stat-label {
    color: #aaa;
    text-transform: uppercase;
    font-size: 0.95rem;
    letter-spacing: 1px;
}

.stat-val {
    color: #fff;
    font-weight: 700;
    font-size: 1.4rem;
    font-family: 'Fira Code', monospace;
}

.stat-diff {
    font-size: 1.1rem;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: 'Fira Code', monospace;
}

.stat-diff.positive {
    color: #10b981;
    background: rgba(16, 185, 129, 0.15);
    font-weight: bold;
}

.stat-diff.negative {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
    font-weight: bold;
}

.stat-diff.neutral {
    color: #888;
    background: rgba(255, 255, 255, 0.1);
}

.scrollbar::-webkit-scrollbar {
    width: 6px;
}

.scrollbar::-webkit-scrollbar-track {
    background: #000;
}

.scrollbar::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

.scrollbar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Log Entries Styling */
.log-entry {
    background: #111;
    border-left: 3px solid #666;
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 0 4px 4px 0;
}

.log-entry h4 {
    color: #fff;
    margin-bottom: 6px;
    font-size: 1.05rem;
}

.log-entry p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Per-Rule Reasoning Toggle */
.rule-item-reasoning {
    cursor: pointer;
}

.rule-item-reasoning .reasoning-inline {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin 0.25s ease;
    margin-top: 0;
}

.rule-item-reasoning.show-reasoning .reasoning-inline {
    max-height: 200px;
    opacity: 1;
    margin-top: 4px;
}

.rule-item-reasoning .derivation-chain {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin 0.25s ease;
    margin-bottom: 0;
}

.rule-item-reasoning.show-reasoning .derivation-chain {
    max-height: 60px;
    opacity: 1;
    margin-bottom: 2px;
}

/* Reasoning Chevron on each rule */
.reasoning-chevron {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: auto;
    flex-shrink: 0;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.reasoning-chevron::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid #555;
    border-bottom: 1.5px solid #555;
    transform: rotate(-45deg);
    transition: border-color 0.2s;
}

.rule-item-reasoning:hover .reasoning-chevron::before {
    border-color: #999;
}

.rule-item-reasoning.show-reasoning .reasoning-chevron {
    transform: rotate(90deg);
}

.rule-item-reasoning.show-reasoning .reasoning-chevron::before {
    border-color: var(--success);
}

/* Per-Step Reasoning Toggle (iteration trace steps) */
.reasoning-step {
    cursor: pointer;
}

.reasoning-step .reasoning-text {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin 0.25s ease;
    margin-top: 0;
}

.reasoning-step.show-reasoning .reasoning-text {
    max-height: 200px;
    opacity: 1;
    margin-top: 2px;
}

.log-entry .rule-list {
    margin-top: 8px;
    padding: 8px;
    background: #000;
    border: 1px solid #222;
    border-radius: 4px;
}

.rule-list .rule-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dotted #333;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
}

.rule-list .rule-item:last-child {
    border-bottom: none;
}

.rule-item.addition {
    color: var(--success);
}

.rule-item.removal {
    color: var(--danger);
    opacity: 0.8;
}

.rule-item.kept {
    color: #888;
}

/* ===== Reasoning Trace Styles ===== */

.reasoning-trace {
    margin-top: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
}

.reasoning-trace-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #666;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
}

.iteration-block {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.iteration-block:last-child {
    border-bottom: none;
}

.iteration-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: #a78bfa;
    margin-bottom: 8px;
    padding: 4px 0;
}

.iteration-result {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 6px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
}

.reasoning-step {
    display: flex;
    gap: 10px;
    padding: 6px 8px;
    margin: 4px 0;
    border-radius: 6px;
    border-left: 2px solid transparent;
    transition: background 0.15s;
}

.reasoning-step:hover {
    background: rgba(255, 255, 255, 0.03);
}

.reasoning-step.method-direct {
    border-left-color: #10b981;
}

.reasoning-step.method-transitive {
    border-left-color: #14b8a6;
}

.reasoning-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    background: #4a5568;
    transition: background 0.2s;
}

.reasoning-step.method-direct .reasoning-dot {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

.reasoning-step.method-transitive .reasoning-dot {
    background: #14b8a6;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

.reasoning-body {
    flex: 1;
    min-width: 0;
}

.reasoning-rule {
    font-family: 'Fira Code', monospace;
    font-size: 0.82rem;
    color: #e2e8f0;
    font-weight: 500;
    margin-bottom: 2px;
}

.reasoning-text {
    font-size: 0.8rem;
    color: #94a3b8;
    line-height: 1.4;
}

/* Rule Item with Reasoning */
.rule-item-reasoning {
    padding: 8px 10px;
    margin: 3px 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.015);
    border: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.15s;
}

.rule-item-reasoning:hover {
    background: rgba(255, 255, 255, 0.04);
}

.rule-item-reasoning.addition {
    border-left: 2px solid #10b981;
}

.rule-item-reasoning.removal {
    border-left: 2px solid #ef4444;
}

.rule-item-reasoning.kept {
    border-left: 2px solid #4a5568;
}

.rule-main {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}

.rule-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    font-family: 'Outfit', sans-serif;
}

.rule-badge.original,
.rule-badge.kept {
    background: rgba(74, 85, 104, 0.3);
    color: #94a3b8;
}

.rule-badge.generated {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.rule-badge.removal {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.rule-badge.unit {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.rule-text {
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
}

.reasoning-inline {
    font-size: 0.78rem;
    color: #64748b;
    line-height: 1.4;
    padding-left: 2px;
    margin-top: 2px;
}

/* Derivation Chain */
.derivation-chain {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Fira Code', monospace;
    font-size: 0.78rem;
    padding: 3px 0;
    flex-wrap: wrap;
    margin-bottom: 2px;
}

.chain-label {
    color: #64748b;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.5px;
}

.chain-path {
    color: #a78bfa;
    font-weight: 500;
}

.chain-arrow {
    color: #4a5568;
}

.chain-source {
    color: #10b981;
}

/* Nullable Positions */
.nullable-positions {
    font-size: 0.8rem;
    color: #94a3b8;
    margin: 4px 0 4px 0;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.pos-badge {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.pos-badge sub {
    font-size: 0.6rem;
    color: #f59e0b;
    opacity: 0.7;
}

/* Collapsible Reasoning Details */
.reasoning-details {
    margin-top: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    overflow: hidden;
}

.reasoning-details-summary {
    padding: 8px 12px;
    font-size: 0.82rem;
    color: #64748b;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
    user-select: none;
    transition: color 0.15s, background 0.15s;
}

.reasoning-details-summary:hover {
    color: #94a3b8;
    background: rgba(255, 255, 255, 0.04);
}

.reasoning-details[open] .reasoning-details-summary {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.reasoning-sub-title {
    font-size: 0.82rem;
    font-weight: 600;
    padding: 6px 0;
    margin-bottom: 4px;
}

/* Concept Line */
.concept-line {
    padding: 10px 14px;
    margin: 8px 0;
    border-left: 3px solid #10b981;
    background: rgba(16, 185, 129, 0.04);
    color: #94a3b8;
    font-size: 0.85rem;
    line-height: 1.5;
    border-radius: 0 6px 6px 0;
}

.rule-transform-container:last-child {
    border-bottom: none !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Graph Legend */
.graph-legend {
    position: absolute;
    top: 50px;
    left: 20px;
    z-index: 100;
    background: rgba(15, 15, 15, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    color: #ccc;
    font-weight: 500;
    white-space: nowrap;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-line {
    width: 14px;
    height: 2px;
    border-radius: 1px;
    flex-shrink: 0;
}

.legend-dash {
    width: 14px;
    height: 2px;
    border-top: 2px dashed #ef4444;
    flex-shrink: 0;
}

/* Grammar Display Rules (Diffs) */
.grammar-rule {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: #0a0a0a;
    border-radius: 4px;
    align-items: start;
    font-size: 1rem;
    border-left: 2px solid #222;
}

.token-removed {
    color: #f87171;
    font-weight: 500;
    text-decoration: line-through;
    opacity: 0.8;
}

.token-added {
    color: #34d399;
    font-weight: 600;
    padding: 0 4px;
    border-bottom: 1px solid rgba(52, 211, 153, 0.3);
}

.token-kept {
    color: #e2e8f0;
}

.token-kept-container {
    display: inline-flex;
    align-items: center;
}

.token-anim-removed-container {
    display: inline-flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    animation: shrinkRemoved 3s forwards cubic-bezier(0.4, 0, 0.2, 1);
}

.token-anim-removed {
    color: #f87171;
    font-weight: 500;
    text-decoration: line-through;
    opacity: 0.8;
}

@keyframes shrinkRemoved {
    0% {
        max-width: 500px;
        opacity: 1;
        margin-right: 0;
    }

    30% {
        max-width: 500px;
        opacity: 1;
        transform: scale(0.95);
    }

    70% {
        max-width: 500px;
        opacity: 0;
        transform: scale(0.9);
    }

    100% {
        max-width: 0px;
        opacity: 0;
        transform: scale(0);
        font-size: 0;
        padding: 0;
        margin-right: 0;
        border: none;
    }
}

.token-anim-added-container {
    display: inline-flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    animation: growAdded 3s forwards cubic-bezier(0.4, 0, 0.2, 1);
}

.token-anim-added {
    color: #34d399;
    font-weight: 600;
}

@keyframes growAdded {
    0% {
        max-width: 0px;
        opacity: 0;
        transform: translateY(-10px);
        font-size: 0;
    }

    30% {
        max-width: 500px;
        opacity: 0;
        transform: translateY(-5px);
        font-size: 1rem;
    }

    100% {
        max-width: 500px;
        opacity: 1;
        transform: translateY(0);
        font-size: 1rem;
    }
}

.pipe {
    color: #333;
    margin: 0 8px;
    font-weight: 300;
}

.rule-lhs {
    color: #fff;
    font-weight: 600;
    width: 35px;
    text-align: right;
    margin-right: 15px;
    font-family: 'Fira Code', monospace;
    padding-top: 2px;
}

.rule-arrow {
    color: #555;
    margin-right: 15px;
    padding-top: 2px;
}

.rule-rhs {
    color: #e2e8f0;
    line-height: 1.6;
    flex: 1;
}

/* Final Compare */
.final-compare-grid {
    display: flex;
    gap: 20px;
    align-items: stretch;
    margin: 2rem 0;
}

.grammar-box {
    flex: 1;
    background: #0a0a0a;
    border: 1px solid #222;
    border-radius: 8px;
    padding: 1.5rem;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.glow-box {
    border-color: #555;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.02);
}

.grammar-box h3 {
    color: #fff;
    text-align: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid #222;
    padding-bottom: 10px;
}

.arrow-container {
    font-size: 2.5rem;
    color: #444;
    display: flex;
    align-items: center;
}

.success-banner {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #111;
    border: 1px solid #333;
    padding: 1.2rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.icon-success {
    font-size: 1.5rem;
    color: var(--success);
}

/* Dynamic Graph Viewer */
.dynamic-graph-viewer {
    position: relative;
    margin-top: 3rem;
    background: #0a0a0a;
    border: 1px solid #222;
    border-radius: 8px;
    padding: 1.5rem;
}

.dynamic-graph-viewer h3 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #fff;
    border-bottom: none;
}

.playback-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.playback-controls .btn {
    padding: 8px 16px;
    font-size: 0.95rem;
}

.playback-controls .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#graph-stage-label {
    font-weight: 600;
    min-width: 250px;
    text-align: center;
    font-size: 1.1rem;
    color: #10b981;
}

/* Animations */
@keyframes slideUpFade {
    0% {
        opacity: 0;
        transform: translateY(40px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-panel {
    opacity: 1;
}


.stage-sets-box {
    background: #111;
    border-left: 3px solid #14b8a6;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 0 4px 4px 0;
    font-family: 'Fira Code', monospace;
    font-size: 1.05rem;
    color: #e2e8f0;
    display: none;
}

.stage-sets-box.active {
    display: block;
}

.stage-sets-box .set-line {
    margin-bottom: 8px;
}

.stage-sets-box .set-line:last-child {
    margin-bottom: 0;
}

.set-label {
    color: #888;
    font-weight: bold;
    margin-right: 10px;
}

.concept-line {
    font-size: 0.85rem;
    color: var(--success);
    background: rgba(16, 185, 129, 0.04);
    padding: 8px 12px;
    border-radius: 6px;
    border-left: 3px solid var(--success);
    margin: 10px 0;
    font-weight: 500;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 10px;
}

.concept-line::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.algo-details {
    background: #0a0a0a;
    border: 1px solid #222;
    border-radius: 6px;
    margin-bottom: 20px;
    overflow: hidden;
}

.algo-details summary {
    padding: 12px 15px;
    cursor: pointer;
    font-weight: bold;
    color: #aaa;
    background: #111;
    user-select: none;
}

.algo-details summary:hover {
    background: #1a1a1a;
    color: #fff;
}

.algo-details pre {
    padding: 15px;
    color: #888;
    font-family: 'Fira Code', monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
}


/* Stage Navigator */
.stage-navigator {
    position: fixed;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
    padding: 10px;
    background: rgba(15, 15, 15, 0.4);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.stage-navigator.visible {
    opacity: 1;
    pointer-events: all;
}

.nav-item {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
    transform: scale(1.1);
}

.nav-item.active {
    background: var(--success);
    border-color: var(--success);
    color: #000;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.nav-item::after {
    content: attr(title);
    position: absolute;
    right: 50px;
    background: #0f0f0f;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    color: #fff;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    border: 1px solid #333;
    transform: translateX(10px);
}

.nav-item:hover::after {
    opacity: 1;
    transform: translateX(0);
}

/* Scroll Progress */
.scroll-progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.05);
}

.scroll-progress-bar {
    height: 100%;
    background: linear-gradient(to right, var(--success), #34d399);
    width: 0%;
    box-shadow: 0 0 10px var(--success);
}

/* Glassmorphism & Enhanced Panels */
.panel {
    background: rgba(15, 15, 15, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
}

.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.1), transparent);
}

.panel.active-stage {
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 40px rgba(16, 185, 129, 0.05);
}

/* Animation on Scroll */
.animate-on-scroll {
    opacity: 1;
    transform: none;
    transition: none;
}

/* Typography & Neon */
.highlight {
    text-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

h2 {
    letter-spacing: -0.5px;
}

/* Smooth Scroll */
html {
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

/* Responsive Tweaks */
@media (max-width: 1024px) {
    .dashboard-grid.full-width {
        grid-template-columns: 1fr;
    }

    .stage-navigator {
        right: 15px;
    }
}

/* ================= STEP-BY-STEP MODE CSS ================= */
#sbs-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #050505;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

#sbs-view.hidden {
    display: none !important;
}

.sbs-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.sbs-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 30px;
    background: #0f0f0f;
    border-bottom: 1px solid #222;
}

.sbs-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 500px;
    margin: 0 20px;
}

.sbs-stage-label {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.sbs-counter-row {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 15px;
}

.sbs-counter {
    font-size: 0.85rem;
    color: #aaa;
    white-space: nowrap;
}

.sbs-progress-track {
    flex: 1;
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
}

.sbs-progress-fill {
    height: 100%;
    background: #fff;
    width: 0%;
    transition: width 0.3s ease, background 0.3s ease;
    box-shadow: 0 0 10px var(--step-color, #fff);
}

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

.sbs-graph-wrapper {
    flex: 2;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: transparent;
    gap: 20px;
}

#sbs-network {
    flex: 1;
    border-radius: 6px;
    border: 1px solid #222;
    background-color: #080808;
    background-image: url('data:image/svg+xml;utf8,<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M 40 0 L 0 0 0 40" fill="none" stroke="%231a1a1a" stroke-width="1"/></pattern></defs><rect width="100%" height="100%" fill="url(%23grid)" /></svg>');
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5);
}

.sbs-grammar-state {
    flex: 0 0 auto;
    background-color: #0b0b0b;
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, transparent 100%);
    border: 1px solid #222;
    border-radius: 6px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    max-height: 350px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02), 0 4px 20px rgba(0, 0, 0, 0.5);
}

.sbs-grammar-header {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 15px;
    border-bottom: 1px solid #222;
    padding-bottom: 8px;
}

.sbs-grammar-content {
    overflow-y: auto;
    line-height: 1.8;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}

.sbs-carousel-wrapper {
    flex: 1;
    border-left: 1px solid #222;
    background: transparent;
    overflow-y: auto;
    padding: 30px 40px;
    position: relative;
    scrollbar-width: none;
    mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
    -webkit-mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
}

.sbs-carousel-wrapper::-webkit-scrollbar {
    display: none;
}

.sbs-carousel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 35vh 0;
    /* Ensures first/last can reach center heavily */
}

.sbs-step {
    padding: 20px;
    border-radius: 6px;
    background: #0f0f0f;
    border: 1px solid #222;
    border-left: 4px solid var(--step-color, #666);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.1;
    transform: scale(0.85) translateX(20px);
    position: relative;
    overflow: hidden;
    filter: blur(2px);
}

.sbs-step::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--step-color), transparent);
    opacity: 0.05;
    pointer-events: none;
}

.sbs-step.past {
    opacity: 0.25;
    transform: scale(0.9) translateX(10px);
    filter: blur(1px);
}

.sbs-step.future {
    opacity: 0.15;
    transform: scale(0.85) translateX(20px);
}

.sbs-step.current {
    opacity: 1;
    transform: scale(1) translateX(0);
    background: #111;
    border-color: #444;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7), 0 0 20px rgba(var(--step-color-rgb, 255, 255, 255), 0.1);
    z-index: 10;
    filter: blur(0);
}

.sbs-step-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Outfit', sans-serif;
}

.sbs-step-rule {
    font-family: 'Fira Code', monospace;
    font-size: 1.1rem;
    color: #fff;
    margin-bottom: 10px;
    padding-right: 60px;
}

.sbs-step-reasoning {
    display: none;
    font-size: 1.05rem;
    color: #e2e8f0;
    line-height: 1.6;
    margin-top: 20px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-left: 3px solid var(--step-color, #666);
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px 8px 8px 4px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

.sbs-step-reasoning::before {
    content: 'Transformation Logic';
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--step-color, #888);
    margin-bottom: 10px;
    font-weight: 700;
    opacity: 0.8;
}

.sbs-step.current .sbs-step-reasoning {
    display: block;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.sbs-step-stage {
    font-size: 0.75rem;
    color: #666;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}