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

    /* Matrix Colors */
    --adjacency-color: #d63b1d;
    --reachability-color: #ff8c42;
    --incidence-color: #2d8f2d;

    /* 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-1509228468518-180dd4864904?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;
}

/* ===== Matrix Type Buttons ===== */
.matrix-type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

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

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

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

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

/* ===== Select & Controls ===== */
.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);
}

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

.speed-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

#speedValue {
    font-weight: 600;
    color: var(--accent-gold);
}

/* ===== 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;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
}

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

.stat-value {
    font-size: 0.9rem;
    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);
}

.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 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;
    overflow-y: auto;
}

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

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

/* ===== Matrices Overview ===== */
.matrices-overview {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.matrix-category {
    background: rgba(255, 255, 255, 0.7);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.3s ease;
}

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

.adjacency-category {
    border-left: 5px solid var(--adjacency-color);
}

.reachability-category {
    border-left: 5px solid var(--reachability-color);
}

.incidence-category {
    border-left: 5px solid var(--incidence-color);
}

.category-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

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

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

.category-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.25rem;
}

.definition-box,
.properties-box,
.application-box {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
}

.definition-box h4,
.properties-box h4,
.application-box h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-red);
    margin-bottom: 0.75rem;
}

.definition-box p,
.application-box p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.formula-box {
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    padding: 0.75rem;
    background: rgba(139, 0, 0, 0.05);
    border-radius: 6px;
    border: 1px solid rgba(139, 0, 0, 0.1);
    color: var(--text-primary);
    line-height: 1.8;
    margin-top: 0.5rem;
}

.properties-box ul {
    list-style: none;
    padding: 0;
}

.properties-box li {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(139, 0, 0, 0.05);
    line-height: 1.5;
}

.properties-box li strong {
    color: var(--text-primary);
    font-weight: 600;
}

.application-box {
    background: rgba(255, 184, 0, 0.1);
    border-left: 3px solid var(--accent-gold);
}

/* ===== Case Display ===== */
.case-description {
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    border-left: 4px solid var(--accent-red);
}

.desc-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.desc-text h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent-red);
    margin-bottom: 0.75rem;
}

.historical-context {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.7;
    text-align: justify;
}

/* ===== Graph SVG ===== */
#graphCanvas {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    min-height: 500px;
}

.graph-svg {
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.edge-line {
    stroke: rgba(139, 0, 0, 0.3);
    stroke-width: 2;
}

.edge-label {
    font-size: 11px;
    fill: var(--text-secondary);
    font-weight: 600;
}

.vertex-circle {
    fill: #fff;
    stroke: var(--accent-red);
    stroke-width: 2.5;
    filter: drop-shadow(0 2px 4px rgba(139, 0, 0, 0.15));
}

.vertex-text {
    font-size: 12px;
    font-weight: 700;
    fill: var(--text-primary);
    pointer-events: none;
}

/* ===== Matrix Table ===== */
.matrix-table {
    margin: 0 auto;
    border-collapse: separate;
    border-spacing: 2px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.matrix-table th {
    padding: 0.75rem 1rem;
    background: var(--accent-red);
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
}

.matrix-table thead th {
    border-bottom: 2px solid rgba(139, 0, 0, 0.3);
}

.matrix-table tbody th {
    background: rgba(214, 59, 29, 0.8);
}

.matrix-table td {
    padding: 0.75rem 1rem;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    min-width: 50px;
    transition: all 0.3s ease;
}

.cell-zero {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-secondary);
}

.cell-one {
    background: rgba(214, 59, 29, 0.15);
    color: var(--accent-red);
    font-weight: 700;
}

.matrix-table td:hover {
    background: rgba(255, 184, 0, 0.3);
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(139, 0, 0, 0.2);
}

/* ===== Matrix Explanation ===== */
.matrix-explanation-box {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    border-left: 4px solid var(--accent-gold);
}

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

.matrix-explanation-box .meaning {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: rgba(255, 184, 0, 0.1);
    border-radius: 8px;
}

.matrix-explanation-box .examples h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.matrix-explanation-box .examples p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.5rem;
    padding-left: 1rem;
}

/* ===== Properties Analysis ===== */
.properties-analysis-box {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
}

.property-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    border-left: 3px solid var(--accent-red);
}

.prop-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 150px;
}

.prop-value {
    font-size: 0.9rem;
    color: var(--text-primary);
    flex: 1;
    text-align: left;
}

/* ===== Philosophy ===== */
.philosophy-box {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.7);
    border-left: 4px solid var(--accent-gold);
    border-radius: 12px;
}

.philosophy-icon {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 1rem;
}

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

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

    .category-content {
        grid-template-columns: 1fr;
    }

    .matrix-type-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .matrix-type-grid {
        grid-template-columns: 1fr;
    }

    .glass-pane {
        padding: 1rem;
    }

    .matrix-table {
        font-size: 0.8rem;
    }

    .matrix-table th,
    .matrix-table td {
        padding: 0.5rem;
        min-width: 35px;
    }
}

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