/* ── Variables ───────────────────────────────────────────── */

:root {
    --bg:      #f8f9fc;
    --bg2:     #f0f1f5;
    --card:    #ffffff;
    --text:    #1a1a2e;
    --text2:   #3d3d5c;
    --muted:   #6b7280;
    --border:  #e2e4ea;
    --cnf:     #2563eb;
    --cnf2:    #1d4ed8;
    --gnf:     #059669;
    --gnf2:    #047857;
    --err:     #dc2626;
    --ok:      #16a34a;
    --accent:  #7c3aed;
    --mono:  'JetBrains Mono', monospace;
    --sans:  'Inter', system-ui, sans-serif;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.03);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.06), 0 12px 40px rgba(0,0,0,.04);
    --transition: .2s ease;
    --glow-cnf: 0 0 20px rgba(37,99,235,.15);
    --glow-gnf: 0 0 20px rgba(5,150,105,.15);
}

[data-theme="dark"] {
    --bg:      #0c0d14;
    --bg2:     #14161f;
    --card:    #1a1d2a;
    --text:    #e5e7eb;
    --text2:   #b0b3bf;
    --muted:   #888da0;
    --border:  #252838;
    --shadow: 0 1px 3px rgba(0,0,0,.2), 0 4px 12px rgba(0,0,0,.15);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.3), 0 12px 40px rgba(0,0,0,.2);
    --glow-cnf: 0 0 30px rgba(37,99,235,.2);
    --glow-gnf: 0 0 30px rgba(5,150,105,.2);
}

/* ── Reset ──────────────────────────────────────────────── */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    transition: background .3s, color .3s;
    overflow-x: hidden;
}
a { text-decoration: none; color: inherit; }
button { font-family: var(--sans); }

/* ── Navbar ─────────────────────────────────────────────── */

.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    background: rgba(248,249,252,.85);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid rgba(226,228,234,.6);
    transition: background .3s, border-color .3s, box-shadow .3s;
}
[data-theme="dark"] .navbar {
    background: rgba(12,13,20,.85);
    border-bottom-color: rgba(37,40,56,.6);
}
.navbar.scrolled {
    box-shadow: 0 1px 8px rgba(0,0,0,.06);
}
.nav-wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nav-brand {
    font-weight: 700;
    font-size: .95rem;
    color: var(--text);
    letter-spacing: -.02em;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color var(--transition);
}
.brand-icon {
    font-size: 1.1rem;
    color: var(--cnf);
    animation: spinSlow 8s linear infinite;
}
@keyframes spinSlow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.nav-links {
    display: flex;
    align-items: center;
    gap: 24px;
}
.nav-link {
    font-size: .82rem;
    font-weight: 500;
    color: var(--muted);
    transition: color var(--transition);
    position: relative;
}
.nav-link::after {
    content: '';
    position: absolute;
    bottom: -4px; left: 0;
    width: 0; height: 2px;
    background: var(--cnf);
    border-radius: 1px;
    transition: width .25s ease;
}
.nav-link:hover { color: var(--text); }
.nav-link:hover::after { width: 100%; }

.theme-toggle {
    width: 34px; height: 34px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: .95rem;
    color: var(--text);
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.theme-toggle:hover { 
    background: var(--border); 
    transform: rotate(20deg);
}

.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}
.nav-hamburger span {
    display: block;
    width: 18px; height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: all .2s;
}

/* ── Hero ────────────────────────────────────────────────── */

.hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--bg);
    overflow: hidden;
    padding: 80px 24px 60px;
}
.hero::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle at 30% 40%, rgba(37,99,235,.06) 0%, transparent 50%),
                radial-gradient(circle at 70% 60%, rgba(5,150,105,.05) 0%, transparent 50%),
                radial-gradient(circle at 50% 80%, rgba(124,58,237,.04) 0%, transparent 40%);
    animation: heroGlow 12s ease-in-out infinite alternate;
}
[data-theme="dark"] .hero::before {
    background: radial-gradient(circle at 30% 40%, rgba(37,99,235,.1) 0%, transparent 50%),
                radial-gradient(circle at 70% 60%, rgba(5,150,105,.08) 0%, transparent 50%),
                radial-gradient(circle at 50% 80%, rgba(124,58,237,.06) 0%, transparent 40%);
}
@keyframes heroGlow {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-3%, -3%) scale(1.05); }
}

#particleCanvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1;
}

.hero-content {
    position: relative;
    z-index: 2;
    max-width: 680px;
    margin: 0 auto;
}
.hero-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--cnf);
    margin-bottom: 20px;
    padding: 6px 16px;
    background: rgba(37,99,235,.06);
    border: 1px solid rgba(37,99,235,.12);
    border-radius: 20px;
}
[data-theme="dark"] .hero-label {
    background: rgba(37,99,235,.1);
    border-color: rgba(37,99,235,.2);
}
.hero-label-dot {
    width: 6px; height: 6px;
    background: var(--cnf);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(.8); }
}

.hero-title {
    margin-bottom: 20px;
}
.hero-line {
    display: block;
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -.03em;
    color: var(--text);
}
.gradient-text {
    background: linear-gradient(135deg, var(--cnf), var(--gnf), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    background-size: 200% 200%;
    animation: gradientShift 4s ease-in-out infinite;
}
@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.hero-desc {
    font-size: .95rem;
    color: var(--muted);
    line-height: 1.75;
    margin-bottom: 32px;
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
}
.hero-desc strong { color: var(--text2); font-weight: 600; }

.hero-btns {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 48px;
}

.hero-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    font-size: .88rem;
    font-weight: 600;
    border-radius: 10px;
    transition: all .25s ease;
    cursor: pointer;
}
.primary-cta {
    background: linear-gradient(135deg, var(--cnf), var(--cnf2));
    color: #fff;
    box-shadow: 0 4px 14px rgba(37,99,235,.3);
}
.primary-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37,99,235,.4);
}
.primary-cta svg { transition: transform .2s; }
.primary-cta:hover svg { transform: translateY(2px); }

.secondary-cta {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.secondary-cta:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--cnf);
}

.hero-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
}
.hero-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.hero-stat-num {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--cnf);
    font-variant-numeric: tabular-nums;
}
.hero-stat-label {
    font-size: .7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
}
.hero-stat-divider {
    width: 1px; height: 32px;
    background: var(--border);
}

.hero-scroll-indicator {
    position: absolute;
    bottom: 24px; left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 2;
}
.hero-scroll-indicator span {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--muted);
    font-weight: 600;
}
.scroll-line {
    width: 1px; height: 32px;
    background: linear-gradient(to bottom, var(--muted), transparent);
    animation: scrollPulse 2s ease-in-out infinite;
}
@keyframes scrollPulse {
    0%, 100% { opacity: 1; height: 32px; }
    50% { opacity: .3; height: 20px; }
}

/* ── Section Headers ─────────────────────────────────────── */

.section-header {
    text-align: center;
    margin-bottom: 40px;
}
.section-tag {
    display: inline-block;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--cnf);
    background: rgba(37,99,235,.06);
    border: 1px solid rgba(37,99,235,.12);
    padding: 4px 14px;
    border-radius: 16px;
    margin-bottom: 12px;
}
[data-theme="dark"] .section-tag {
    background: rgba(37,99,235,.1);
    border-color: rgba(37,99,235,.2);
}
.section-title {
    font-size: clamp(1.3rem, 3vw, 1.8rem);
    font-weight: 800;
    letter-spacing: -.02em;
    color: var(--text);
    margin-bottom: 8px;
}
.section-subtitle {
    font-size: .9rem;
    color: var(--muted);
    max-width: 480px;
    margin: 0 auto;
}

/* ── Features ────────────────────────────────────────────── */

.wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
}

.features-section {
    padding: 72px 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.feature-card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: all .3s ease;
    overflow: hidden;
}
.feature-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--cnf), var(--gnf));
    opacity: 0;
    transition: opacity .3s;
}
.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(37,99,235,.2);
}
.feature-card:hover::before { opacity: 1; }

.feature-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 14px;
    transition: transform .3s;
}
.feature-card:hover .feature-icon { transform: scale(1.1); }
.feature-icon-cnf { background: rgba(37,99,235,.08); color: var(--cnf); }
.feature-icon-gnf { background: rgba(5,150,105,.08); color: var(--gnf); }
.feature-icon-cyk { background: rgba(124,58,237,.08); color: var(--accent); }
.feature-icon-ff { background: rgba(245,158,11,.08); color: #d97706; }
.feature-icon-tree { background: rgba(37,99,235,.08); color: var(--cnf); }
.feature-icon-export { background: rgba(5,150,105,.08); color: var(--gnf); }
[data-theme="dark"] .feature-icon-cnf { background: rgba(37,99,235,.12); }
[data-theme="dark"] .feature-icon-gnf { background: rgba(5,150,105,.12); }
[data-theme="dark"] .feature-icon-cyk { background: rgba(124,58,237,.12); }
[data-theme="dark"] .feature-icon-ff { background: rgba(245,158,11,.12); }
[data-theme="dark"] .feature-icon-tree { background: rgba(37,99,235,.12); }
[data-theme="dark"] .feature-icon-export { background: rgba(5,150,105,.12); }

.feature-card h3 {
    font-size: .9rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}
.feature-card p {
    font-size: .82rem;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 12px;
}
.feature-tag {
    display: inline-block;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: var(--bg2);
    padding: 2px 8px;
    border-radius: 4px;
}

/* ── How It Works ────────────────────────────────────────── */

.how-it-works-section {
    padding: 72px 0;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}

.steps-timeline {
    position: relative;
    max-width: 600px;
    margin: 0 auto;
}
.timeline-line {
    position: absolute;
    left: 20px; top: 0; bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, var(--cnf), var(--gnf), var(--accent));
    border-radius: 1px;
    opacity: .3;
}
.timeline-step {
    position: relative;
    display: flex;
    gap: 20px;
    padding: 0 0 36px 0;
}
.timeline-step:last-child { padding-bottom: 0; }
.timeline-dot {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cnf), var(--cnf2));
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    z-index: 1;
    box-shadow: 0 4px 12px rgba(37,99,235,.25);
    transition: transform .3s;
}
.timeline-step:hover .timeline-dot { transform: scale(1.1); }
.timeline-content {
    padding-top: 8px;
}
.timeline-content h3 {
    font-size: .95rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.timeline-content p {
    font-size: .84rem;
    color: var(--muted);
    line-height: 1.6;
}

/* ── Image Scan ──────────────────────────────────────────── */

.image-scan-area {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.image-drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 36px 20px;
    text-align: center;
    cursor: pointer;
    transition: all .25s ease;
    background: var(--bg2);
    position: relative;
}
.image-drop-zone:hover,
.image-drop-zone.drag-over {
    border-color: var(--cnf);
    background: rgba(37,99,235,.03);
}
[data-theme="dark"] .image-drop-zone:hover,
[data-theme="dark"] .image-drop-zone.drag-over {
    background: rgba(37,99,235,.06);
}
.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.drop-icon {
    color: var(--muted);
    opacity: .5;
    transition: all .25s;
}
.image-drop-zone:hover .drop-icon {
    opacity: .8;
    color: var(--cnf);
    transform: scale(1.05);
}
.drop-text {
    font-size: .88rem;
    color: var(--text2);
    font-weight: 500;
}
.drop-text .link-btn {
    color: var(--cnf);
    font-size: .88rem;
    font-weight: 600;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.drop-hint {
    font-size: .72rem;
    color: var(--muted);
}

.image-preview-wrap {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg2);
    text-align: center;
}
.image-preview-wrap img {
    max-width: 100%;
    max-height: 280px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    padding: 8px;
}
.image-remove-btn {
    position: absolute;
    top: 8px; right: 8px;
    width: 28px; height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,.6);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .2s;
    line-height: 1;
}
.image-remove-btn:hover {
    background: var(--err);
    transform: scale(1.1);
}

.scan-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}
.scan-controls .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.scan-progress {
    display: flex;
    align-items: center;
    gap: 12px;
}
.scan-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.scan-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--cnf), var(--gnf));
    border-radius: 3px;
    transition: width .3s ease;
}
.scan-status {
    font-size: .78rem;
    color: var(--muted);
    font-weight: 500;
    white-space: nowrap;
}

.scan-result {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.scan-result-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}
.scan-result-label {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.scan-result-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.scan-result-text {
    display: block;
    width: 100%;
    margin: 0;
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: .85rem;
    line-height: 1.7;
    color: var(--text);
    background: var(--card);
    border: none;
    border-bottom: 1px solid var(--border);
    resize: vertical;
    outline: none;
    min-height: 80px;
    max-height: 220px;
    transition: background .2s;
}
.scan-result-text:focus {
    background: var(--bg2);
}
.scan-edit-hint {
    font-size: .7rem;
    color: var(--muted);
    padding: 6px 14px;
    background: var(--bg2);
    border-top: none;
}

/* ── Converter ───────────────────────────────────────────── */

.converter-section {
    padding: 72px 0 80px;
    background: var(--bg);
}

/* ── Cards ───────────────────────────────────────────────── */

.card, .glass-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow .3s ease;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
    flex-wrap: wrap;
}
.card-head h2 {
    font-size: .95rem;
    font-weight: 700;
}
.card-icon { display: none; }

/* ── Tabs ────────────────────────────────────────────────── */

.tab-group { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tab {
    padding: 6px 16px;
    border: none;
    background: var(--bg2);
    font-size: .8rem;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    transition: all var(--transition);
}
.tab + .tab { border-left: 1px solid var(--border); }
.tab.active { background: var(--cnf); color: #fff; }
.tab:hover:not(.active) { background: var(--bg); }
.tab-icon { display: none; }

/* ── Syntax ref ──────────────────────────────────────────── */

.ref-box { margin-bottom: 14px; font-size: .8rem; color: var(--muted); }
.ref-box summary {
    cursor: pointer; font-weight: 600; color: var(--text2);
    padding: 4px 0; user-select: none;
}
.ref-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 3px 16px;
    margin-top: 6px;
}
.ref-list li { padding-left: 12px; position: relative; }
.ref-list li::before { content: ''; position: absolute; left: 0; top: 9px; width: 4px; height: 4px; background: var(--border); border-radius: 50%; }
kbd {
    display: inline-block;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 5px;
    font-family: var(--mono);
    font-size: .76rem;
    line-height: 1.7;
    transition: all .2s;
}

/* ── Editor ──────────────────────────────────────────────── */

.editor-wrap {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color var(--transition);
}
.editor-wrap:focus-within { border-color: var(--cnf); }
.editor-gutter {
    display: flex;
    flex-direction: column;
    padding: 12px 0;
    min-width: 36px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    text-align: center;
    font-family: var(--mono);
    font-size: .75rem;
    line-height: 1.7;
    color: var(--muted);
    user-select: none;
}
.editor-gutter span { padding: 0 8px; min-height: calc(1.7 * .88rem); }

textarea#grammarInput {
    width: 100%;
    min-height: 140px;
    font-family: var(--mono);
    font-size: .88rem;
    line-height: 1.7;
    padding: 12px 14px;
    border: none;
    background: var(--bg2);
    color: var(--text);
    resize: vertical;
    outline: none;
    transition: background .2s, color .2s;
}
textarea#grammarInput::placeholder { color: #aaa; }
[data-theme="dark"] textarea#grammarInput { background: var(--bg2); }
[data-theme="dark"] textarea#grammarInput::placeholder { color: #555; }

/* ── Examples ────────────────────────────────────────────── */

.example-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    flex-wrap: wrap;
    font-size: .8rem;
}
.example-row > span { color: var(--muted); font-weight: 600; }
.example-row button {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    font-size: .78rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text);
    transition: all var(--transition);
}
.example-row button:hover { background: var(--bg2); }
.danger-text { color: var(--err) !important; }
.danger-text:hover { background: rgba(220,38,38,.04) !important; }

/* ── Form mode ───────────────────────────────────────────── */

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr 80px;
    gap: 10px;
    margin-bottom: 14px;
}
.field-row label {
    display: flex; flex-direction: column;
    font-size: .78rem; font-weight: 600; color: var(--muted); gap: 3px;
}
.field-row input {
    padding: 7px 9px;
    font-family: var(--mono);
    font-size: .84rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    outline: none;
    background: var(--bg2);
    color: var(--text);
    transition: border-color var(--transition);
}
.field-row input:focus { border-color: var(--cnf); }

.prod-section { margin-bottom: 6px; }
.prod-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px; font-size: .82rem; font-weight: 600;
}
.link-btn {
    background: none; border: none; color: var(--cnf);
    font-size: .8rem; font-weight: 600; cursor: pointer; font-family: var(--sans);
}
.link-btn:hover { text-decoration: underline; }

.production-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.prod-lhs {
    width: 44px; text-align: center; padding: 6px;
    font-family: var(--mono); font-weight: 600;
    border: 1px solid var(--border); border-radius: 4px;
    outline: none; font-size: .88rem; color: var(--cnf);
    background: var(--bg2);
}
.prod-lhs:focus { border-color: var(--cnf); }
.arr { color: var(--muted); font-family: var(--mono); }
.prod-rhs {
    flex: 1; padding: 6px 9px;
    font-family: var(--mono); font-size: .84rem;
    border: 1px solid var(--border); border-radius: 4px;
    outline: none; background: var(--bg2); color: var(--text);
}
.prod-rhs:focus { border-color: var(--cnf); }
.row-x {
    width: 26px; height: 26px;
    border: none; background: none;
    color: var(--muted); font-size: 1rem;
    cursor: pointer; border-radius: 4px;
}
.row-x:hover { background: rgba(220,38,38,.06); color: var(--err); }

/* ── Buttons ─────────────────────────────────────────────── */

.btn-row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: .84rem;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    transition: all .25s ease;
    position: relative;
    overflow: hidden;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-cnf { 
    background: linear-gradient(135deg, var(--cnf), var(--cnf2)); 
    box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.btn-cnf:hover { box-shadow: 0 4px 14px rgba(37,99,235,.35); }
.btn-gnf { 
    background: linear-gradient(135deg, var(--gnf), var(--gnf2)); 
    box-shadow: 0 2px 8px rgba(5,150,105,.25);
}
.btn-gnf:hover { box-shadow: 0 4px 14px rgba(5,150,105,.35); }
.btn-both { 
    background: linear-gradient(135deg, #475569, #334155); 
    box-shadow: 0 2px 8px rgba(71,85,105,.25);
}
.btn-both:hover { box-shadow: 0 4px 14px rgba(71,85,105,.35); }
.btn-sm { padding: 8px 18px; }
.btn-shimmer { display: none; }

.keyboard-hint {
    margin-top: 12px;
    font-size: .7rem;
    color: var(--muted);
    text-align: center;
}

/* ── Error ───────────────────────────────────────────────── */

.err {
    margin-top: 14px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--err);
    font-size: .84rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}
[data-theme="dark"] .err { background: #1f1215; border-color: #3f1d20; color: #f87171; }
.err-icon { font-size: .95rem; }

/* ── Tags ────────────────────────────────────────────────── */

.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    background: var(--bg2);
    color: var(--muted);
    transition: all .2s;
}
.cnf-tag { background: rgba(37,99,235,.08); color: var(--cnf); }
.gnf-tag { background: rgba(5,150,105,.08); color: var(--gnf); }

/* ── Verification ────────────────────────────────────────── */

.verify-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 4px;
    font-size: .72rem; font-weight: 600;
    border: 1px solid var(--border);
}
.verify-badge.pass { background: #f0fdf4; border-color: #bbf7d0; color: #16a34a; }
.verify-badge.fail { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
[data-theme="dark"] .verify-badge.pass { background: #052e16; border-color: #166534; color: #4ade80; }
[data-theme="dark"] .verify-badge.fail { background: #1f1215; border-color: #3f1d20; color: #f87171; }
.verify-icon { font-size: .8rem; }

/* ── Results ─────────────────────────────────────────────── */

.results { padding-bottom: 32px; }

.result-heading {
    font-size: 1.05rem;
    font-weight: 700;
    margin-top: 32px;
    margin-bottom: 6px;
    padding-left: 12px;
    border-left: 3px solid var(--border);
}
.heading-icon { display: none; }
.cnf-heading { border-color: var(--cnf); color: var(--cnf); }
.gnf-heading { border-color: var(--gnf); color: var(--gnf); }

.form-desc {
    font-size: .82rem;
    color: var(--muted);
    margin-bottom: 14px;
    padding-left: 15px;
}

/* ── Grammar display ─────────────────────────────────────── */

.grammar-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    font-family: var(--mono);
    font-size: .85rem;
    line-height: 1.85;
    transition: all .2s;
}
.grammar-box .production-line {
    display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap;
    padding: 1px 4px; border-radius: 3px;
    transition: background .1s; cursor: default;
}
.grammar-box .production-line:hover { background: rgba(37,99,235,.04); }
.grammar-box .production-line.highlight { background: rgba(37,99,235,.08); }
.grammar-box .variable { color: var(--cnf); font-weight: 600; }
.grammar-box .arrow-symbol { color: var(--muted); margin: 0 3px; }
.grammar-box .terminal { color: #92400e; font-weight: 500; }
[data-theme="dark"] .grammar-box .terminal { color: #fbbf24; }
.grammar-box .pipe { color: var(--muted); margin: 0 4px; }
.grammar-box .epsilon { color: #7c3aed; font-style: italic; }

/* ── Meta ────────────────────────────────────────────────── */

.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.meta-item {
    font-size: .75rem; color: var(--muted); background: var(--bg2);
    padding: 3px 10px; border-radius: 4px;
}
.meta-item strong { color: var(--text); font-weight: 600; }

/* ── Steps ───────────────────────────────────────────────── */

.step {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.step-head {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 16px; cursor: pointer;
    user-select: none; transition: background .1s;
}
.step-head:hover { background: var(--bg2); }
.step-num {
    width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.cnf-step .step-num { background: var(--cnf); }
.gnf-step .step-num { background: var(--gnf); }
.unchanged .step-num { background: #9ca3af; }
.step-title { font-weight: 600; font-size: .84rem; flex: 1; }
.step-badge {
    font-size: .65rem; padding: 2px 8px; border-radius: 3px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
}
.step-badge.changed { background: rgba(37,99,235,.08); color: var(--cnf); }
.step-badge.unchanged { background: var(--bg2); color: #9ca3af; }
.gnf-step .step-badge.changed { background: rgba(5,150,105,.08); color: var(--gnf); }
.step-chevron {
    color: var(--muted); font-size: .7rem;
    transition: transform .2s ease;
}
.step-chevron.open { transform: rotate(180deg); }
.step-body {
    border-top: 1px solid var(--border);
    padding: 14px 16px; display: none;
}
.step-body.open { display: block; }
.step-desc { font-size: .82rem; color: var(--muted); line-height: 1.6; margin-bottom: 10px; }
.step-detail {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 6px; padding: 10px 14px;
    font-size: .8rem; font-family: var(--mono); line-height: 1.6;
    color: var(--text); margin-bottom: 8px;
}
.step-detail-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600; margin-bottom: 4px; font-family: var(--sans);
}

/* ── Final card ──────────────────────────────────────────── */

.final { margin-top: 14px; }
.cnf-border { border-top: 2px solid var(--cnf); }
.gnf-border { border-top: 2px solid var(--gnf); }
.final .card-head .action-btns { display: flex; gap: 4px; align-items: center; }

/* ── Action buttons ──────────────────────────────────────── */

.action-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    font-size: .72rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--muted);
    transition: all var(--transition);
}
.action-btn:hover { background: var(--bg2); color: var(--text); }

/* ── Toast ───────────────────────────────────────────────── */

.toast {
    position: fixed; bottom: 20px; right: 20px;
    padding: 10px 18px; background: var(--card); border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12); font-size: .82rem; font-weight: 600;
    z-index: 100; display: flex; align-items: center; gap: 6px;
    transform: translateY(80px); opacity: 0;
    transition: all .25s ease; border-left: 3px solid var(--ok);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-icon { font-size: .9rem; }

/* ── FIRST/FOLLOW ────────────────────────────────────────── */

.ff-section {
    margin-top: 10px; padding: 16px; background: var(--bg2);
    border: 1px solid var(--border); border-radius: 6px;
}
.ff-table {
    width: 100%; border-collapse: collapse;
    font-size: .82rem; font-family: var(--mono); margin-top: 8px;
}
.ff-table th {
    padding: 7px 12px; background: var(--bg);
    font-family: var(--sans); font-size: .75rem;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600; text-align: left;
    border-bottom: 2px solid var(--border);
}
.ff-table td {
    padding: 7px 12px; border-bottom: 1px solid var(--border); vertical-align: top;
}
.ff-table tr:last-child td { border-bottom: none; }
.ff-var { color: var(--cnf); font-weight: 600; }
.ff-set { color: var(--text); }
.ff-terminal { color: #92400e; font-weight: 500; }
[data-theme="dark"] .ff-terminal { color: #fbbf24; }

/* ── CYK / Test Section ─────────────────────────────────── */

.test-section, .cyk-section {
    margin-top: 14px; padding: 18px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
}
.test-section h3, .cyk-section h3 { font-size: .9rem; font-weight: 700; margin-bottom: 8px; }
.test-desc { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.test-input-row, .cyk-input-row { display: flex; gap: 6px; margin-bottom: 10px; }
#cykInput, #gnfTestInput {
    flex: 1; padding: 7px 12px; font-family: var(--mono); font-size: .86rem;
    border: 1px solid var(--border); border-radius: 6px;
    outline: none; background: var(--bg2); color: var(--text);
    transition: border-color var(--transition);
}
#cykInput:focus, #gnfTestInput:focus { border-color: var(--cnf); }
.cyk-result {
    padding: 10px 14px; border-radius: 6px;
    font-size: .84rem; font-weight: 600; display: none;
}
.cyk-result.accept { background: #f0fdf4; border: 1px solid #bbf7d0; color: #16a34a; display: block; }
.cyk-result.reject { background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; display: block; }
[data-theme="dark"] .cyk-result.accept { background: #052e16; border-color: #166534; color: #4ade80; }
[data-theme="dark"] .cyk-result.reject { background: #1f1215; border-color: #3f1d20; color: #f87171; }
.cyk-table-wrap { overflow-x: auto; margin-top: 10px; }
.cyk-table {
    border-collapse: collapse; font-family: var(--mono);
    font-size: .78rem; margin: 0 auto;
}
.cyk-table td, .cyk-table th {
    border: 1px solid var(--border); padding: 5px 10px;
    text-align: center; min-width: 44px;
}
.cyk-table th { background: var(--bg2); font-weight: 600; font-size: .7rem; color: var(--muted); }
.cyk-table .cyk-filled { background: rgba(37,99,235,.03); font-weight: 600; }
.cyk-table .cyk-start-cell { background: rgba(37,99,235,.08); font-weight: 700; color: var(--cnf); }

/* ── Statistics ──────────────────────────────────────────── */

.stats-dashboard { margin-top: 14px; }
.stats-grid {
    display: grid; grid-template-columns: repeat(6, 1fr);
    gap: 8px; margin-bottom: 10px;
}
.stat-card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 6px; padding: 10px 6px; text-align: center;
}
.stat-num {
    font-size: 1.2rem; font-weight: 700; color: var(--cnf);
}
.stat-label {
    font-size: .65rem; color: var(--muted); text-transform: uppercase;
    letter-spacing: .02em; margin-top: 2px; font-weight: 600;
}
.stat-props { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.stat-prop {
    font-size: .7rem; padding: 2px 8px; border-radius: 3px;
    font-weight: 600; display: inline-flex; align-items: center; gap: 3px;
}
.stat-prop.yes { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.stat-prop.no { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.stat-prop.info { background: rgba(37,99,235,.05); color: var(--cnf); border: 1px solid rgba(37,99,235,.15); }
[data-theme="dark"] .stat-prop.yes { background: #052e16; border-color: #166534; color: #4ade80; }
[data-theme="dark"] .stat-prop.no { background: #1f1215; border-color: #3f1d20; color: #f87171; }
[data-theme="dark"] .stat-prop.info { background: rgba(37,99,235,.08); border-color: rgba(37,99,235,.2); color: #60a5fa; }

/* ── Step Controls ───────────────────────────────────────── */

.step-controls {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 6px; box-shadow: var(--shadow); flex-wrap: wrap;
}
.step-ctrl-btn {
    width: 28px; height: 28px; border: 1px solid var(--border);
    border-radius: 4px; background: var(--card);
    cursor: pointer; font-size: .75rem; color: var(--text);
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.step-ctrl-btn:hover { background: var(--bg2); }
.step-ctrl-btn.active { background: var(--err); color: #fff; border-color: var(--err); }
.play-btn { font-size: .6rem; letter-spacing: -1px; }
.step-counter {
    font-family: var(--mono); font-size: .78rem; font-weight: 600;
    color: var(--muted); min-width: 40px; text-align: center;
}
.step-progress-bar {
    flex: 1; min-width: 60px; height: 3px;
    background: var(--border); border-radius: 2px; overflow: hidden;
}
.step-progress-fill {
    height: 100%; background: var(--cnf); border-radius: 2px;
    transition: width .25s ease; width: 0%;
}

/* ── Diff ────────────────────────────────────────────────── */

.diff-section { margin: 14px 0; }
.diff-container {
    display: grid; grid-template-columns: 1fr auto 1fr;
    gap: 10px; align-items: stretch;
}
.diff-pane { flex: 1; }
.diff-label {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
    font-weight: 600; color: var(--muted); margin-bottom: 4px; padding-left: 2px;
}
.diff-label.cnf-label { color: var(--cnf); }
.diff-label.gnf-label { color: var(--gnf); }
.diff-grammar { font-size: .8rem !important; line-height: 1.7 !important; }
.diff-arrow {
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: var(--muted);
}

/* ── Parse Tree ──────────────────────────────────────────── */

.derivation-section {
    margin-top: 14px; padding: 18px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
}
.derivation-section h3 { font-size: .9rem; font-weight: 700; margin-bottom: 6px; }
.derivation-steps {
    display: flex; flex-wrap: wrap; gap: 4px;
    margin-bottom: 12px; padding: 10px;
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 6px; font-family: var(--mono);
    font-size: .8rem; line-height: 1.8; max-height: 180px; overflow-y: auto;
}
.deriv-step {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 1px 6px; border-radius: 3px; cursor: pointer;
    transition: background var(--transition);
}
.deriv-step:hover { background: rgba(37,99,235,.06); }
.deriv-step.active { background: rgba(37,99,235,.1); font-weight: 600; }
.deriv-arrow { color: var(--muted); font-size: .9rem; margin: 0 3px; vertical-align: middle; }
.deriv-step .deriv-arrow { font-size: .65rem; margin: 0 1px; }
.deriv-var { color: var(--cnf); font-weight: 600; }
.deriv-term { color: #92400e; font-weight: 500; }
[data-theme="dark"] .deriv-term { color: #fbbf24; }
.tree-container {
    width: 100%; overflow-x: auto;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg2);
}
#treeCanvas, #gnfTreeCanvas { display: block; margin: 0 auto; }

/* ── Confetti (kept minimal for verify) ──────────────────── */

.confetti-container {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 9999; overflow: hidden;
}
.confetti-piece {
    position: absolute; width: 6px; height: 6px; border-radius: 1px;
    animation: confettiFall 2s ease-in forwards;
}

/* ── Back to Top ─────────────────────────────────────────── */

.back-to-top {
    position: fixed;
    bottom: 20px; right: 20px;
    width: 36px; height: 36px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text);
    box-shadow: var(--shadow);
    z-index: 99;
    opacity: 0;
    transform: translateY(10px);
    transition: all var(--transition);
    display: flex; align-items: center; justify-content: center;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); }
.back-to-top:hover { background: var(--bg2); }

/* ── Footer ──────────────────────────────────────────────── */

footer {
    text-align: center;
    padding: 40px 24px;
    color: var(--muted);
    font-size: .78rem;
    border-top: 1px solid var(--border);
    background: var(--bg2);
}
.footer-content {
    max-width: 960px;
    margin: 0 auto;
}
.footer-brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}
.footer-brand .brand-icon {
    color: var(--cnf);
    font-size: 1.1rem;
}
.footer-content > p {
    margin-bottom: 14px;
    color: var(--muted);
}
.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
}
.footer-links a {
    font-size: .8rem;
    font-weight: 500;
    color: var(--muted);
    transition: color var(--transition);
}
.footer-links a:hover { color: var(--cnf); }

/* ── Tooltip ─────────────────────────────────────────────── */

.tooltip {
    position: absolute; background: var(--text); color: var(--bg);
    font-size: .72rem; padding: 4px 8px; border-radius: 4px;
    pointer-events: none; z-index: 100; white-space: nowrap;
    opacity: 0; transform: translateY(3px);
    transition: all .15s ease;
}
.tooltip.visible { opacity: 1; transform: translateY(0); }

/* ── Animations ───────────────────────────────────────── */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes highlightFlash { 0% { background: rgba(37,99,235,.15); } 100% { background: transparent; } }
@keyframes confettiFall {
    0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes countUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Reveal on Scroll ────────────────────────────────────── */

.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity .7s ease, transform .7s ease;
    transition-delay: var(--delay, 0s);
}
.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Utility ─────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .features-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .diff-container { grid-template-columns: 1fr; }
    .diff-arrow { transform: rotate(90deg); justify-self: center; }
    .field-row { grid-template-columns: 1fr 1fr; }
    .field-row .short { grid-column: span 2; }
    .nav-links { display: none; }
    .nav-hamburger { display: flex; }
    .nav-links.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 56px; left: 0; right: 0;
        background: rgba(248,249,252,.95);
        backdrop-filter: blur(16px);
        border-bottom: 1px solid var(--border);
        padding: 16px 24px;
        gap: 14px;
    }
    [data-theme="dark"] .nav-links.open {
        background: rgba(12,13,20,.95);
    }
    .hero { min-height: 90vh; padding-top: 100px; }
    .hero-stats { gap: 16px; }
    .hero-stat-num { font-size: 1.2rem; }
    .steps-timeline { padding-left: 0; }
}

@media (max-width: 520px) {
    .features-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .btn-row { flex-direction: column; }
    .hero-line { font-size: 1.5rem; }
    .hero-btns { flex-direction: column; align-items: center; }
    .hero-stats { flex-direction: column; gap: 12px; }
    .hero-stat-divider { width: 40px; height: 1px; }
    .footer-links { flex-direction: column; gap: 8px; }
}
