:root {
    /* Theme Colors */
    --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;
    --success-green: #27c93f;
    --danger-red: #ff3b30;
    --equivalence-color: #5b8dee;
    --implication-color: #9b59b6;

    /* 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;
    --font-mono: 'Times New Roman', 'Courier New', monospace;
}

* {
    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-1518770660439-4636190af475?q=80&w=2574&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
}

.app-container {
    width: 92vw;
    height: 92vh;
    max-width: 1800px;
    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: 360px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.2rem;
    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: 1.9rem;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

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

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

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

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

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

/* ===== Relation Type Buttons ===== */
.relation-type-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}

.type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 1rem 0.8rem;
    border-radius: 12px;
    border: 2px solid rgba(139, 0, 0, 0.2);
    background: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
}

.type-btn:hover {
    border-color: var(--accent-red);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.type-btn.active {
    border-color: var(--accent-red);
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.05), rgba(255, 180, 0, 0.05));
}

.type-icon {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-red);
}

.type-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== Inputs ===== */
.apple-select, .apple-textarea, .apple-input {
    padding: 9px 12px;
    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.85rem;
    transition: all 0.2s ease;
}

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

.apple-textarea {
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

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

/* ===== Domain Input ===== */
.domain-input {
    display: flex;
    gap: 0.5rem;
}

.domain-input .apple-input {
    flex: 1;
}

.small-btn {
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid var(--accent-red);
    background: var(--accent-red);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.small-btn:hover {
    background: var(--accent-hover);
}

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

.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: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--accent-red);
    cursor: pointer;
    margin-top: -7px;
    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: 10px;
    border-radius: 10px;
    font-size: 0.85rem;
    border: 1px solid rgba(139, 0, 0, 0.1);
}

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

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

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

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

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

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

/* ===== Main Stage ===== */
.visualizer-stage {
    flex-grow: 1;
    padding: 1.5rem;
    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: 1.5rem;
    overflow-y: auto;
}

.visualization-container {
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
}

/* ===== Sections ===== */
.section {
    width: 100%;
    max-width: 1300px;
    margin: 0 auto;
}

.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;
}

/* ===== Concept Cards ===== */
.concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 1.5rem;
}

.concept-card {
    background: rgba(255, 255, 255, 0.8);
    border-radius: 14px;
    padding: 1.5rem;
    border: 2px solid transparent;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.concept-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.concept-card.equivalence-card {
    border-color: var(--equivalence-color);
}

.concept-card.implication-card {
    border-color: var(--implication-color);
}

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

.concept-symbol {
    font-size: 2.5rem;
    font-weight: 700;
}

.equivalence-card .concept-symbol {
    color: var(--equivalence-color);
}

.implication-card .concept-symbol {
    color: var(--implication-color);
}

.concept-header h3 {
    font-size: 1.3rem;
    color: var(--text-primary);
}

.concept-definition {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.concept-formula {
    background: rgba(139, 0, 0, 0.05);
    padding: 0.8rem;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    text-align: center;
    color: var(--accent-red);
    font-weight: 600;
    margin-bottom: 1rem;
    border-left: 4px solid var(--accent-red);
}

.concept-meaning {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    font-style: italic;
    padding: 0.8rem;
    background: rgba(255, 180, 0, 0.05);
    border-radius: 8px;
}

.concept-meaning strong {
    color: var(--accent-red);
}

/* ===== Case Display ===== */
.case-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 248, 240, 0.9));
    border-radius: 16px;
    padding: 2rem;
    border: 2px solid var(--accent-red);
    box-shadow: var(--shadow-md);
}

.case-card.equivalence {
    border-color: var(--equivalence-color);
}

.case-card.implication {
    border-color: var(--implication-color);
}

.case-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.case-header h3 {
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--accent-red);
}

.case-type-badge {
    padding: 0.5rem 1.2rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
}

.case-type-badge.equivalence {
    background: var(--equivalence-color);
}

.case-type-badge.implication {
    background: var(--implication-color);
}

.case-formulas {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.formula-item {
    flex: 1;
    background: rgba(255, 255, 255, 0.8);
    padding: 1.2rem;
    border-radius: 12px;
    border: 2px solid rgba(139, 0, 0, 0.1);
}

.formula-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.formula-content {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    color: var(--accent-red);
    font-weight: 700;
    text-align: center;
}

.relation-symbol {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-gold);
}

.case-description {
    padding-top: 1rem;
    border-top: 2px solid rgba(139, 0, 0, 0.1);
}

.case-description p {
    margin-bottom: 0.6rem;
    font-size: 0.95rem;
    line-height: 1.6;
}

.case-description strong {
    color: var(--accent-red);
}

/* ===== Truth Table ===== */
.truth-table-wrapper {
    overflow-x: auto;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    padding: 1rem;
}

.truth-comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.truth-comparison-table th {
    background: var(--accent-red);
    color: #fff;
    padding: 0.6rem 0.4rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
}

.truth-comparison-table th.pred-header {
    background: var(--accent-gold);
    font-size: 0.7rem;
}

.truth-comparison-table td {
    padding: 0.5rem 0.3rem;
    text-align: center;
    border: 1px solid rgba(139, 0, 0, 0.1);
}

.truth-comparison-table tbody tr {
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.truth-comparison-table tbody tr.visible {
    opacity: 1;
    transform: translateY(0);
}

.truth-comparison-table tbody tr.valid-row {
    background: rgba(39, 201, 63, 0.1);
}

.truth-comparison-table tbody tr.invalid-row {
    background: rgba(255, 107, 107, 0.1);
}

.index-cell {
    font-weight: 700;
    color: var(--accent-red);
    font-size: 0.75rem;
}

.value-cell.true {
    color: var(--success-green);
    font-weight: 700;
}

.value-cell.false {
    color: #ff6b6b;
}

.truth-cell {
    font-weight: 700;
    font-size: 0.85rem;
}

.truth-cell.true {
    color: var(--success-green);
}

.truth-cell.false {
    color: #ff6b6b;
}

.relation-cell {
    font-weight: 700;
    font-size: 0.85rem;
}

.relation-cell.valid {
    color: var(--success-green);
}

.relation-cell.invalid {
    color: #ff6b6b;
}

/* ===== Verification Result ===== */
.result-box {
    display: flex;
    gap: 2rem;
    padding: 2rem;
    border-radius: 14px;
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.4s ease;
}

.result-box.visible {
    opacity: 1;
    transform: scale(1);
}

.result-box.valid {
    background: rgba(39, 201, 63, 0.1);
    border: 3px solid var(--success-green);
}

.result-box.invalid {
    background: rgba(255, 107, 107, 0.1);
    border: 3px solid #ff6b6b;
}

.result-icon {
    font-size: 4rem;
    font-weight: 700;
}

.result-box.valid .result-icon {
    color: var(--success-green);
}

.result-box.invalid .result-icon {
    color: #ff6b6b;
}

.result-content {
    flex: 1;
}

.result-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.result-title.success {
    color: var(--success-green);
}

.result-title.fail {
    color: #ff6b6b;
}

.result-stats {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
}

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

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

.result-explanation {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.result-explanation strong {
    color: var(--accent-red);
    font-size: 1.1rem;
}

/* ===== Relation Chain ===== */
.chain-visualization {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 14px;
}

.chain-node {
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.1), rgba(255, 180, 0, 0.1));
    padding: 1.2rem 1.8rem;
    border-radius: 12px;
    border: 2px solid var(--accent-red);
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s ease;
}

.chain-node.visible {
    opacity: 1;
    transform: scale(1);
}

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

/* ===== Philosophy Section ===== */
.philosophy-content {
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.08), rgba(255, 180, 0, 0.08));
    padding: 2rem;
    border-radius: 14px;
    border: 2px solid var(--accent-gold);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s ease;
}

.philosophy-content.visible {
    opacity: 1;
    transform: translateY(0);
}

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

.phil-icon {
    font-size: 2.5rem;
}

.phil-header h3 {
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--accent-red);
}

.phil-body {
    margin-bottom: 1.5rem;
}

.phil-text {
    font-size: 1.05rem;
    line-height: 1.9;
    color: var(--text-primary);
    text-indent: 2em;
}

.phil-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.phil-tag {
    padding: 0.5rem 1.2rem;
    background: var(--accent-red);
    color: #fff;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

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

/* ===== Responsive ===== */
@media (max-width: 1400px) {
    .concept-grid {
        grid-template-columns: 1fr;
    }

    .case-formulas {
        flex-direction: column;
        gap: 1rem;
    }

    .relation-symbol {
        transform: rotate(90deg);
    }
}

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

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

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