:root {
    --formula-purple: #7c3aed;
    --logic-blue: #3b82f6;
    --syntax-green: #10b981;
    --warning-red: #ef4444;
    --governance-gold: #f59e0b;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --bg-light: #f8fafc;
    --border-color: #e2e8f0;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);

    --font-family: "Noto Serif SC", "Outfit", serif;
    --font-mono: "JetBrains Mono", monospace;
    --font-title: "Ma Shan Zheng", cursive;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #f3e7ff 0%, #ddd6fe 50%, #c4b5fd 100%);
    color: var(--text-dark);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 96vw;
    height: 92vh;
    max-width: 1900px;
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 3px solid var(--formula-purple);
}

/* Header */
.main-header {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--formula-purple) 0%, #6d28d9 100%);
    border-bottom: 3px solid #6d28d9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 1.6rem;
    color: white;
    margin-bottom: 4px;
}

.highlight {
    font-family: var(--font-title);
    font-size: 1.9rem;
    color: #fde047;
}

.subtitle {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    font-style: italic;
}

.header-tabs {
    display: flex;
    gap: 6px;
}

.tab-btn {
    padding: 8px 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.tab-btn.active {
    background: white;
    color: var(--formula-purple);
    border-color: white;
}

/* Main Stage */
.main-stage {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 360px;
    overflow: hidden;
}

.tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

.content-area {
    padding: 30px;
    background: linear-gradient(180deg, var(--bg-light) 0%, white 100%);
}

.content-area h2 {
    font-size: 1.8rem;
    color: var(--formula-purple);
    margin-bottom: 8px;
    font-family: var(--font-title);
}

.section-desc {
    color: var(--text-light);
    margin-bottom: 24px;
}

/* BNF Section */
.bnf-definition {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.def-card,
.policy-metaphor {
    background: white;
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 2px solid var(--border-color);
}

.def-card h3,
.policy-metaphor h3 {
    font-size: 1.2rem;
    color: var(--formula-purple);
    margin-bottom: 16px;
}

.bnf-rules {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 20px;
    border-radius: 10px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 2;
}

.bnf-rule {
    margin: 4px 0;
}

.bnf-rule.indent {
    padding-left: 40px;
}

.rule-name {
    color: #4ec9b0;
}

.rule-or {
    color: #c586c0;
    font-weight: bold;
}

.rule-def {
    color: #ce9178;
}

.metaphor-item {
    margin: 16px 0;
    padding: 12px;
    background: var(--bg-light);
    border-radius: 8px;
    border-left: 4px solid var(--governance-gold);
}

.metaphor-item strong {
    display: block;
    color: var(--formula-purple);
    margin-bottom: 4px;
}

.metaphor-item p {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 4px;
}

/* N-ary Section */
.formula-builder {
    background: white;
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow-md);
}

.builder-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.builder-controls label {
    font-weight: 600;
}

.builder-controls input[type="range"] {
    flex: 1;
}

.builder-controls span {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--formula-purple);
    min-width: 30px;
    text-align: center;
}

.variables-display {
    display: flex;
    gap: 12px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.var-chip {
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--formula-purple), #a78bfa);
    color: white;
    border-radius: 20px;
    font-family: var(--font-mono);
    font-weight: 700;
}

.formula-examples .example-formula {
    margin: 12px 0;
    padding: 16px;
    background: var(--bg-light);
    border-radius: 10px;
    border-left: 4px solid var(--logic-blue);
}

.example-formula strong {
    display: block;
    margin-bottom: 8px;
    color: var(--formula-purple);
}

/* Hierarchy Section */
.precedence-table {
    background: white;
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

.precedence-table table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.precedence-table th,
.precedence-table td {
    padding: 12px;
    text-align: left;
    border: 1px solid var(--border-color);
}

.precedence-table th {
    background: var(--formula-purple);
    color: white;
    font-weight: 600;
}

.precedence-table tbody tr:hover {
    background: rgba(124, 58, 237, 0.05);
}

.precedence-table td:nth-child(2) {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.2rem;
    text-align: center;
}

.parsing-demo {
    background: white;
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow-md);
}

.demo-input {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.demo-input input {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 1rem;
}

.demo-input button {
    padding: 12px 24px;
    background: var(--formula-purple);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.demo-input button:hover {
    background: #6d28d9;
}

.parse-tree {
    min-height: 200px;
    padding: 20px;
    background: var(--bg-light);
    border-radius: 10px;
}

/* Symbol Section */
.symbolization-examples {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.example-box,
.interactive-symbolizer {
    background: white;
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow-md);
}

.symbol-item {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 16px;
    align-items: center;
    margin: 20px 0;
    padding: 16px;
    background: var(--bg-light);
    border-radius: 10px;
}

.natural-lang,
.symbol-form {
    font-size: 0.9rem;
}

.natural-lang strong,
.symbol-form strong {
    display: block;
    margin-bottom: 8px;
    color: var(--formula-purple);
}

.arrow {
    font-size: 2rem;
    color: var(--governance-gold);
    font-weight: bold;
}

.symbol-form .formula {
    margin-top: 8px;
    padding: 10px;
    background: white;
    border-radius: 6px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    border: 2px solid var(--formula-purple);
}

.interactive-symbolizer textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.9rem;
    margin: 16px 0;
    resize: vertical;
}

.interactive-symbolizer button {
    width: 100%;
    padding: 12px;
    background: var(--syntax-green);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.interactive-symbolizer button:hover {
    background: #059669;
}

.symbolized-output {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-light);
    border-radius: 10px;
    min-height: 100px;
}

/* Sidebar */
.sidebar {
    background: linear-gradient(180deg, #faf5ff 0%, #f3e8ff 100%);
    border-left: 3px solid var(--formula-purple);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.panel-section {
    background: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.panel-icon {
    font-size: 1.2rem;
}

.panel-header h3 {
    font-size: 1rem;
    color: var(--formula-purple);
}

.concept-content,
.insight-content {
    font-size: 0.85rem;
    line-height: 1.7;
}

.concept-content h4,
.insight-content h4 {
    color: var(--governance-gold);
    margin: 12px 0 6px 0;
    font-size: 0.95rem;
}

.concept-content h4:first-child,
.insight-content h4:first-child {
    margin-top: 0;
}

.concept-content p,
.insight-content p {
    color: var(--text-light);
    margin-bottom: 10px;
}

.formula-examples-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.example-item {
    padding: 12px;
    background: var(--bg-light);
    border-radius: 8px;
    border-left: 3px solid var(--formula-purple);
}

.example-item strong {
    display: block;
    margin-bottom: 6px;
    color: var(--formula-purple);
    font-size: 0.85rem;
}

.example-item p {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-dark);
}