:root {
    /* Chinese Culture Theme */
    --app-bg: #fdfbf7;
    --sidebar-bg: rgba(255, 248, 240, 0.8);
    --glass-border: rgba(214, 59, 29, 0.2);
    --text-primary: #8b0000;
    --text-secondary: #a05a5a;
    --accent-red: #d63b1d;
    --accent-gold: #ffb400;
    --accent-hover: #b32b12;
    --danger-red: #ff3b30;

    /* Token Colors */
    --token-noun: #d63b1d;
    --token-verb: #ffb400;
    --token-adj: #ff8c75;
    --token-quant: #8b0000;
    --token-other: #a05a5a;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(139, 0, 0, 0.08);
    --shadow-md: 0 8px 24px rgba(139, 0, 0, 0.12);
    --shadow-lg: 0 20px 40px rgba(139, 0, 0, 0.15);

    --font-family: "Noto Serif SC", "Outfit", serif;
    --font-title: "Ma Shan Zheng", cursive;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--app-bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url('https://images.unsplash.com/photo-1547618120-dddb5e551d3e?q=80&w=2574&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
}

.app-container {
    width: 90vw;
    height: 90vh;
    max-width: 1600px;
    background: rgba(255, 252, 245, 0.85);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 340px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.window-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 0.5rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.red {
    background: #ff5f56;
    border: 1px solid #e0443e;
}

.dot.yellow {
    background: #ffbd2e;
    border: 1px solid #dea123;
}

.dot.green {
    background: #27c93f;
    border: 1px solid #1aab29;
}

h1 {
    font-family: var(--font-title);
    font-size: 2rem;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: -5px;
}

.highlight {
    color: var(--accent-red);
}

.controls-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-grow: 1;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Select & Textarea ===== */
.apple-select {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(139, 0, 0, 0.2);
    background: #fff;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.apple-select:hover {
    border-color: var(--accent-red);
}

.apple-textarea {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(139, 0, 0, 0.2);
    background: #fff;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    resize: vertical;
    transition: all 0.2s ease;
}

.apple-textarea:focus {
    outline: none;
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(214, 59, 29, 0.1);
}

/* ===== Token Mode Buttons ===== */
.token-mode-buttons {
    display: flex;
    gap: 8px;
}

.mode-btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(139, 0, 0, 0.2);
    background: #fff;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

.mode-btn.active {
    background: var(--accent-red);
    color: #fff;
    border-color: var(--accent-red);
}

/* ===== Buttons ===== */
.apple-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: var(--font-family);
    gap: 8px;
}

.action-btn {
    background: var(--accent-red);
    color: white;
    width: 100%;
    box-shadow: var(--shadow-md);
}

.action-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.danger-btn {
    background: rgba(139, 0, 0, 0.1);
    color: var(--text-primary);
    width: 100%;
}

.danger-btn:hover {
    background: rgba(139, 0, 0, 0.2);
}

.apple-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== Range Slider ===== */
input[type=range] {
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--accent-red);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border: 2px solid #fff;
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(139, 0, 0, 0.1);
    border-radius: 2px;
}

/* ===== Info Panel ===== */
.info-panel {
    background: rgba(255, 255, 255, 0.6);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--text-primary);
    border: 1px solid rgba(139, 0, 0, 0.1);
}

#statusText {
    font-weight: 700;
    color: var(--accent-red);
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.stats-display {
    display: flex;
    gap: 16px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

.stat-label {
    color: var(--text-secondary);
    font-weight: 600;
}

.stat-value {
    color: var(--accent-red);
    font-weight: 700;
    font-size: 1rem;
}

.actions-footer {
    display: flex;
    gap: 10px;
}

/* ===== Main Stage ===== */
.visualizer-stage {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.glass-pane {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 16px;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 2rem;
    position: relative;
    overflow-y: auto;
}

.visualization-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: center;
}

/* ===== Sections ===== */
.section {
    width: 100%;
    max-width: 900px;
}

.section-title {
    font-family: var(--font-title);
    font-size: 1.4rem;
    color: var(--accent-red);
    margin-bottom: 1rem;
    text-align: center;
    letter-spacing: 0.05em;
}

/* ===== Original Text ===== */
.text-display {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid rgba(139, 0, 0, 0.15);
}

.poem-lines {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.poem-line {
    font-size: 1.2rem;
    line-height: 1.8;
    color: var(--text-primary);
    font-weight: 500;
}

.poem-line .char {
    display: inline-block;
    transition: all 0.3s ease;
}

/* ===== Arrow Section ===== */
.arrow-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0;
}

.flow-arrow {
    width: 60px;
    height: 80px;
    animation: flowDown 2s ease-in-out infinite;
}

@keyframes flowDown {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    50% {
        transform: translateY(10px);
        opacity: 1;
    }
}

.process-label {
    font-size: 0.9rem;
    color: var(--accent-red);
    font-weight: 700;
    letter-spacing: 0.1em;
}

/* ===== Tokens Display ===== */
.tokens-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    border: 1px solid rgba(139, 0, 0, 0.15);
    min-height: 120px;
}

.token-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 10px;
    border: 2px solid var(--token-color, #ccc);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    opacity: 0;
    animation: fadeInToken 0.4s ease forwards;
}

@keyframes fadeInToken {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.token-item.active {
    transform: scale(1.15);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    border-width: 3px;
    z-index: 10;
}

.token-item.processed {
    background: var(--token-color);
    border-color: var(--token-color);
}

.token-item.processed .token-text {
    color: #fff;
    font-weight: 700;
}

.token-item.processed .token-label {
    color: rgba(255, 255, 255, 0.9);
}

.token-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.token-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Predicate Logic Section ===== */
.predicate-section {
    margin-top: 2rem;
}

.predicate-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.logic-explanation {
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.1) 0%, rgba(255, 180, 0, 0.1) 100%);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid rgba(139, 0, 0, 0.2);
}

.explanation-title {
    font-family: var(--font-title);
    font-size: 1.2rem;
    color: var(--accent-red);
    margin-bottom: 1rem;
    font-weight: 600;
}

.symbol-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 1rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    border: 1px solid rgba(139, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.legend-item:hover {
    background: rgba(255, 255, 255, 1);
    border-color: var(--accent-red);
    transform: translateX(4px);
}

.legend-item .symbol {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-red);
    min-width: 50px;
    text-align: center;
    font-family: 'Times New Roman', serif;
}

.legend-item .desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== Formulas Display ===== */
.formulas-display {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.formula-section {
    background: rgba(255, 255, 255, 0.7);
    padding: 1.2rem;
    border-radius: 12px;
    border: 1px solid rgba(139, 0, 0, 0.15);
    animation: slideInFromLeft 0.5s ease;
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.formula-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-red);
    margin-bottom: 0.4rem;
    font-family: var(--font-family);
}

.formula-section-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-style: italic;
}

.formula-items {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.formula-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 1.2rem;
    background: #fff;
    border-radius: 10px;
    border-left: 4px solid var(--formula-color, #d63b1d);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.formula-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.formula-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.formula-original {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 80px;
    font-family: var(--font-family);
}

.formula-arrow {
    font-size: 1.5rem;
    color: var(--accent-gold);
    font-weight: 700;
}

.formula-logic {
    flex: 1;
    font-size: 1rem;
    font-family: 'Times New Roman', 'Courier New', monospace;
    color: var(--accent-red);
    font-weight: 600;
    letter-spacing: 0.02em;
    background: rgba(214, 59, 29, 0.05);
    padding: 0.5rem 1rem;
    border-radius: 6px;
}

/* ===== Tree Section ===== */
.tree-section {
    margin-top: 1rem;
}

#treeSvg {
    background: rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    border: 1px solid rgba(139, 0, 0, 0.15);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
        height: 95vh;
    }

    .sidebar {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
    }

    .visualizer-stage {
        padding: 1rem;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(139, 0, 0, 0.05);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--accent-red);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-hover);
}
