: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;

    /* Inference Rule Colors */
    --us-color: #d63b1d;
    --es-color: #0066cc;
    --eg-color: #ff8c42;
    --ug-color: #8b3a8b;

    /* 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-1551882547-ff40c63fe5fa?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.5rem;
}

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

/* ===== Rule Type Buttons Grid ===== */
.rule-type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.rule-type-btn {
    padding: 1rem 0.75rem;
    background: rgba(255, 255, 255, 0.5);
    border: 1.5px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1.3;
    font-family: var(--font-family);
}

.rule-type-btn .rule-sub {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    margin-top: 4px;
    color: var(--text-secondary);
}

.rule-type-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
    background: rgba(255, 255, 255, 0.7);
}

.rule-type-btn.active {
    background: #fff;
    border-color: var(--accent-red);
    box-shadow: var(--shadow-md);
}

/* ===== Select Dropdown ===== */
.apple-select {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s ease;
}

.apple-select:hover {
    border-color: var(--accent-red);
    background: rgba(255, 255, 255, 0.8);
}

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

.apple-select option {
    background: #fff;
    color: var(--text-primary);
}

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

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    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.5);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-primary);
    border: 1px solid rgba(139, 0, 0, 0.1);
}

.info-panel p {
    margin-bottom: 8px;
    line-height: 1.5;
}

.stats-display {
    display: flex;
    gap: 1rem;
    margin-top: 8px;
}

.stat-item {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

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

/* ===== 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);
}

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

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

.glass-pane {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.4);
    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;
}

/* ===== Section Blocks ===== */
.section {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    transition: all 0.3s ease;
}

.section:hover {
    background: rgba(255, 255, 255, 0.75);
    box-shadow: var(--shadow-sm);
}

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

/* ===== Rules Grid ===== */
.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.rule-card {
    background: rgba(255, 255, 255, 0.7);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.25rem;
    transition: all 0.2s ease;
}

.rule-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    background: rgba(255, 255, 255, 0.85);
}

.us-card {
    border-color: rgba(214, 59, 29, 0.4);
}

.us-card:hover {
    border-color: var(--us-color);
}

.es-card {
    border-color: rgba(0, 102, 204, 0.4);
}

.es-card:hover {
    border-color: var(--es-color);
}

.eg-card {
    border-color: rgba(255, 140, 66, 0.4);
}

.eg-card:hover {
    border-color: var(--eg-color);
}

.ug-card {
    border-color: rgba(139, 58, 139, 0.4);
}

.ug-card:hover {
    border-color: var(--ug-color);
}

.rule-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.rule-icon {
    font-size: 1.5rem;
}

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

.rule-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rule-formula {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    line-height: 1.6;
    text-align: center;
    padding: 1rem;
    background: rgba(139, 0, 0, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(139, 0, 0, 0.1);
    color: var(--text-primary);
}

.rule-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.rule-meaning {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0.75rem;
    background: rgba(255, 184, 0, 0.1);
    border-radius: 8px;
    border-left: 3px solid var(--accent-gold);
}

.rule-meaning strong {
    color: var(--accent-gold);
}

/* ===== Case Container ===== */
.case-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.case-header {
    text-align: center;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.case-name {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--accent-red);
    font-family: var(--font-title);
}

.case-rule-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(214, 59, 29, 0.1);
    border: 1px solid rgba(214, 59, 29, 0.3);
    color: var(--accent-red);
}

.case-premises {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.premise-item {
    padding: 1rem;
    background: rgba(0, 102, 204, 0.05);
    border: 1px solid rgba(0, 102, 204, 0.2);
    border-radius: 12px;
    border-left: 4px solid var(--es-color);
}

.premise-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.premise-text {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: var(--text-primary);
}

.case-conclusion {
    padding: 1rem;
    background: rgba(214, 59, 29, 0.05);
    border: 1px solid rgba(214, 59, 29, 0.2);
    border-radius: 12px;
    border-left: 4px solid var(--us-color);
}

.conclusion-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.conclusion-text {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: var(--text-primary);
}

/* ===== Inference Steps ===== */
.inference-steps-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.inference-step {
    display: grid;
    grid-template-columns: 50px 1fr 180px 80px;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    transition: all 0.2s ease;
    opacity: 0;
    transform: translateX(-20px);
    animation: slideIn 0.5s ease forwards;
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.inference-step:hover {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: var(--shadow-sm);
}

.step-number {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-red);
    border-radius: 50%;
    font-size: 1rem;
    font-weight: 700;
    color: white;
    box-shadow: var(--shadow-sm);
}

.step-statement {
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.step-justification {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.step-rule-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.8);
    border: 1.5px solid var(--glass-border);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.step-rule-tag.rule-US {
    background: rgba(214, 59, 29, 0.1);
    border-color: var(--us-color);
    color: var(--us-color);
}

.step-rule-tag.rule-ES {
    background: rgba(0, 102, 204, 0.1);
    border-color: var(--es-color);
    color: var(--es-color);
}

.step-rule-tag.rule-EG {
    background: rgba(255, 140, 66, 0.1);
    border-color: var(--eg-color);
    color: var(--eg-color);
}

.step-rule-tag.rule-UG {
    background: rgba(139, 58, 139, 0.1);
    border-color: var(--ug-color);
    color: var(--ug-color);
}

/* ===== Diagram Container ===== */
.diagram-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    padding: 1.5rem;
}

.diagram-flow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.diagram-flow-horizontal {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 2rem;
}

.diagram-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.diagram-node {
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    text-align: center;
    min-width: 180px;
    opacity: 0;
    transform: scale(0.9);
    animation: popIn 0.5s ease forwards;
    box-shadow: var(--shadow-sm);
}

@keyframes popIn {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.diagram-node.premise-node {
    background: rgba(0, 102, 204, 0.08);
    border-color: var(--es-color);
}

.diagram-node.conclusion-node {
    background: rgba(214, 59, 29, 0.08);
    border-color: var(--us-color);
}

.diagram-node.intermediate-node {
    background: rgba(255, 140, 66, 0.08);
    border-color: var(--eg-color);
}

.node-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.node-content {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.diagram-arrow {
    width: 2px;
    height: 40px;
    background: linear-gradient(to bottom, rgba(139, 0, 0, 0.3), rgba(139, 0, 0, 0.1));
    position: relative;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
    animation-delay: 0.3s;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.diagram-arrow::after {
    content: '▼';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.1rem;
    color: var(--accent-gold);
}

.diagram-arrow-up::after {
    content: '▲';
    top: -10px;
    bottom: auto;
}

.diagram-rule-label {
    padding: 4px 10px;
    background: rgba(255, 184, 0, 0.15);
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-gold);
    margin: -8px 0;
    z-index: 1;
    border: 1px solid rgba(255, 184, 0, 0.3);
}

/* ===== Conclusion Display ===== */
.conclusion-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.conclusion-box {
    padding: 1.5rem;
    background: rgba(45, 143, 45, 0.08);
    border: 2px solid rgba(45, 143, 45, 0.4);
    border-radius: 12px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.conclusion-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    to {
        left: 100%;
    }
}

.conclusion-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.conclusion-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2d8f2d;
    margin-bottom: 0.75rem;
}

.conclusion-formula {
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
}

.conclusion-explanation {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ===== Philosophy Content ===== */
.philosophy-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.philosophy-block {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.6);
    border-left: 4px solid var(--accent-gold);
    border-radius: 12px;
    opacity: 0;
    transform: translateY(20px);
    animation: slideUp 0.6s ease forwards;
}

@keyframes slideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.philosophy-block h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.philosophy-icon {
    font-size: 1.3rem;
}

.philosophy-block p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.8;
    text-align: justify;
}

.philosophy-quote {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 184, 28, 0.1);
    border-radius: 8px;
    border-left: 3px solid var(--accent-gold);
    font-style: italic;
    color: var(--text-primary);
    font-size: 0.85rem;
}

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

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

    .rules-grid {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }

    .inference-step {
        grid-template-columns: 45px 1fr;
        gap: 0.75rem;
    }

    .step-justification,
    .step-rule-tag {
        grid-column: 2;
    }

    .diagram-flow-horizontal {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .app-container {
        width: 95vw;
    }

    .glass-pane {
        padding: 1rem;
    }

    .section-title {
        font-size: 1.2rem;
    }

    .rule-type-grid {
        grid-template-columns: 1fr;
    }

    .rules-grid {
        grid-template-columns: 1fr;
    }

    .inference-step {
        grid-template-columns: 1fr;
    }

    .step-number {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
}

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

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

::-webkit-scrollbar-thumb {
    background: rgba(214, 59, 29, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(214, 59, 29, 0.5);
}
