/* Basic Setup */
html {
    /* 锁定基础字号，整体比默认略小一号，平衡本地与线上视觉效果 */
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body, html {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f9f9f9;
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* Prevent body scroll */
}

h1, h2, h3, h4 {
    color: #333;
}

h1 {
    text-align: center;
    margin-top: 0;
}

/* Layout */
.container {
    display: flex;
    flex-direction: row;
    height: 100vh;
}

.sidebar-left {
    width: 320px;
    flex-shrink: 0;
    background-color: #f0f0f0;
    padding: 24px 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    overflow-y: auto;
    height: 100vh;
    box-sizing: border-box; /* Include padding in height */
}

.sidebar-right {
    width: 350px;
    flex-shrink: 0;
    background-color: #f0f0f0;
    padding: 20px;
    box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    overflow-y: auto;
    height: 100vh;
    box-sizing: border-box;
}

.main-content {
    flex-grow: 1;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
    min-width: 0; /* Allow main content to shrink */
}

/* Sidebar sections */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.sidebar-header h2 {
    font-size: 1.3rem;
    margin: 0;
}

.instructions-button,
.primary-btn,
.tertiary-btn {
    border: 1px solid #3d5afe;
    color: #3d5afe;
    background-color: transparent;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.instructions-button:hover,
.tertiary-btn:hover {
    background-color: rgba(61, 90, 254, 0.1);
}

.primary-btn {
    background-color: #3d5afe;
    color: #fff;
    border-radius: 24px;
    padding: 10px 24px;
    font-size: 0.95rem;
}

.primary-btn:hover {
    box-shadow: 0 6px 16px rgba(61, 90, 254, 0.35);
}

.tertiary-btn {
    width: 100%;
    margin-top: 12px;
}

.sidebar-section {
    margin-bottom: 28px;
}

.sidebar-section h3 {
    margin: 0 0 12px;
    font-size: 1rem;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cs-topic-tree,
.calculus-tree {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tree-course,
.tree-core,
.tree-topic,
.cs-topic-button,
.cs-category-button {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 12px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1.4;
    transition: all 0.2s ease;
    text-align: left;
}

/* CS Category Button - Visual distinction for main categories */
.cs-category-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px solid #495057;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 12px 14px;
    margin-bottom: 4px;
}

.cs-category-button:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    border-color: #343a40;
}

.cs-category-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.cs-category-name {
    font-weight: 600;
    color: #212529;
}

/* CS Topic Buttons - Sub-topics with indentation */
.cs-topic-button {
    margin-left: 24px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    font-weight: 400;
    font-size: 0.85rem;
    padding: 8px 10px;
}

.cs-topic-button:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.cs-topic-button.active {
    background: #e3f2fd;
    border-color: #2196f3;
    color: #1976d2;
    font-weight: 500;
}

/* Select All Checkbox - Inside category button */
.cs-select-all-checkbox {
    margin-left: auto;
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: #2563eb;
    flex-shrink: 0;
    margin-right: 0;
}

.tree-course > .course-checkbox,
.tree-core > .core-summary {
    margin-left: auto;
}

/* Calculus I - Blue theme */
.tree-course.calculus-i {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: #5DADE2;
    color: #1565c0;
}

.tree-course.calculus-i:hover {
    background: linear-gradient(135deg, #bbdefb 0%, #90caf9 100%);
    border-color: #2874A6;
}

/* Calculus II - Green theme */
.tree-course.calculus-ii {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-color: #82E0AA;
    color: #2e7d32;
}

.tree-course.calculus-ii:hover {
    background: linear-gradient(135deg, #c8e6c9 0%, #a5d6a7 100%);
    border-color: #239B56;
}

/* Generic hover for other elements (not Calculus I/II) */
.tree-core:hover:not(.disabled),
.tree-topic:hover:not(.disabled),
.cs-topic-button:hover,
.cs-category-button:hover {
    border-color: #9ca3af;
    background-color: #f1f5f9;
}

.tree-course.active,
.tree-core.active,
.tree-topic.active,
.cs-topic-button.active {
    border-color: #2563eb;
    background-color: #dbeafe;
    color: #1d4ed8;
}

.tree-core,
.tree-topic {
    margin-left: 16px;
}

.tree-topic {
    font-weight: 500;
    text-align: left;
}

/* Disabled state for course children */
.tree-core.disabled,
.tree-topic.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    background-color: #f5f5f5;
}

.tree-core.disabled .tree-core-left,
.tree-topic.disabled .topic-label {
    color: #9ca3af;
}

.tree-topic:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    background-color: #f5f5f5;
}

.tree-course-left,
.tree-core-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    text-align: left;
}

.core-summary {
    font-size: 0.78rem;
    color: #6b7280;
}

.tree-toggle-icon {
    font-size: 0.85rem;
    opacity: 0.8;
}

.tree-children {
    display: none;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}

.tree-children.open {
    display: flex;
}

.course-checkbox {
    margin-right: 8px;
    accent-color: #2563eb;
}

.topic-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: left;
    align-items: flex-start;
}

.topic-label small {
    font-size: 0.75rem;
    color: #6b7280;
}

.course-selection-summary {
    font-size: 0.85rem;
    color: #6b7280;
    text-align: right;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.chart-container {
    flex-grow: 1; /* Make chart container fill remaining space */
    width: auto;
    min-height: 0; /* Important for flex-grow to work in a column */
    border: 1px solid #ddd;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 16px 18px;
    margin: 0 8px; /* Leave a small gap on both sides so the white panel doesn't visually sit on top of the gray sidebars */
    gap: 12px;
}

#chart {
    width: 100%;
    height: 100%;
}

/* Main header */
.main-title-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.main-title-group h1 {
    text-align: left; /* 覆盖全局 h1 居中，确保标题在中间区域左对齐 */
    margin: 0;
}

.main-title-group .main-subtitle {
    text-align: left;
}

.main-subtitle {
    margin: 0;
    font-size: 0.9rem;
    color: #6b7280;
}

.main-header-right {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

/* View tabs (list vs full map) */
.view-tabs {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px;
    background-color: #e5e7eb;
    align-self: flex-start;
}

.view-tab {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s ease;
}

.view-tab.active {
    background-color: #ffffff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
}

.view-tab:not(.active):hover {
    color: #111827;
}

/* Calc list panel */
.calc-list-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
}

.calc-list-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.cs-selection-summary {
    font-size: 0.85rem;
    color: #374151;
    max-width: 55%;
}

.calc-list-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
}

.calc-filter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: #4b5563;
}

.calc-filter-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

#connection-threshold {
    width: 120px;
}

#connection-threshold-value {
    font-variant-numeric: tabular-nums;
    min-width: 1.2em;
    text-align: right;
    color: #111827;
    font-weight: 600;
}

#calc-sort-mode {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background-color: #f9fafb;
}

.calc-list-empty {
    margin-top: 8px;
}

.calc-topic-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

.calc-topic-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 6px;
    border-radius: 999px;
    background-color: transparent;
    transition: box-shadow 0.15s ease, background-color 0.15s ease;
    flex-wrap: wrap;
}

.calc-topic-row.active {
    box-shadow: 0 0 0 2px #2563eb33;
    background-color: #eff6ff;
}

.calc-pill {
    flex: 1;
    max-width: 100%;
    min-width: 0;
    border-radius: 999px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 5px rgba(15, 23, 42, 0.25);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.calc-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.35);
    filter: brightness(1.03);
}

.calc-pill-label {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-pill-meta {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Category colors：统一为同一套偏蓝渐变，类别只在文本中体现，颜色仅编码连接强度 */
.calc-pill--limits {
    background: linear-gradient(135deg, #60a5fa, #1d4ed8);
}

.calc-pill--derivatives {
    background: linear-gradient(135deg, #60a5fa, #1d4ed8);
}

.calc-pill--sequences {
    background: linear-gradient(135deg, #60a5fa, #1d4ed8);
}

.calc-pill--integrals {
    background: linear-gradient(135deg, #60a5fa, #1d4ed8);
}

.calc-pill--other {
    background: linear-gradient(135deg, #60a5fa, #1d4ed8);
}

/* Calculus II pills：使用绿色渐变，与图中 Calculus II 节点保持一致 */
.calc-pill--calculus-ii {
    background: linear-gradient(135deg, #4CAF7D, #1F7A4A);
}

/* 无匹配 rationale 时的灰色状态 */
.calc-pill--no-rationale {
    background: linear-gradient(135deg, #e5e7eb, #9ca3af);
    color: #111827;
}

/* Heat levels：通过亮度/饱和度/透明度拉开强弱差异 */
.calc-pill--heat-1 {
    /* 弱连接：最亮、最淡、稍微透明 */
    filter: brightness(1.25) saturate(0.9);
    opacity: 0.85;
}

.calc-pill--heat-2 {
    /* 中连接：基准蓝色，不额外加强或削弱 */
    filter: brightness(1.0) saturate(1.0);
    opacity: 1;
}

.chart-panel {
    flex: 1;
    min-height: 0;
}

/* Rationale Display (in right sidebar) */
#rationale-display {
    margin-top: 0;
}

#rationale-display h3 {
    margin-top: 0;
}
#rationale-display h4 {
    margin-bottom: 5px;
    font-size: 1.1rem;
}
#rationale-level {
    font-size: 0.9rem;
    font-style: italic;
    color: #666;
    margin-top: 0;
}

#rationale-content h5 {
    margin-bottom: 5px;
    margin-top: 15px;
    color: #0056b3;
    border-bottom: 1px solid #eee;
    padding-bottom: 3px;
}
.rationale-item {
    font-size: 0.85rem;
    line-height: 1.4;
    margin-bottom: 10px;
    padding: 8px;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #eee;
}
.rationale-item strong {
    color: #333;
}

/* Graph Styles */
.zoom-layer {
    cursor: grab;
}

.link {
    stroke: #64748b;
    stroke-opacity: 0.5;
    stroke-width: 1.5px;
    transition: all 0.3s ease;
    marker-end: url(#arrowhead);
}

.link:hover {
    stroke: #475569;
    stroke-opacity: 0.8;
    stroke-width: 2px;
}

.node {
    cursor: pointer;
    transition: filter 0.2s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.node:hover {
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
}

.node-circle {
    stroke: #fff;
    stroke-width: 2.5px;
    transition: all 0.3s ease;
}

/* Calculus I - 蓝色渐变 */
.node-circle.calc-i { 
    fill: url(#gradient-calc-i);
}

/* Calculus II - 绿色渐变 */
.node-circle.calc-ii { 
    fill: url(#gradient-calc-ii);
}

.node-label {
    font-size: 12px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 600;
    pointer-events: none;
    fill: #2c3e50;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

/* Highlight/Faded/Selected States */
.node.selected .node-circle {
    stroke: #e74c3c;
    stroke-width: 4px;
    filter: drop-shadow(0 0 8px rgba(231, 76, 60, 0.6));
}

.node.cs-highlight .node-circle {
    stroke: #ff4d4f;
    stroke-width: 3px;
    filter: drop-shadow(0 0 12px rgba(255, 77, 79, 0.75));
}

.node.incoming .node-circle {
    stroke: #2563eb;
    stroke-width: 3px;
    filter: drop-shadow(0 0 10px rgba(37, 99, 235, 0.55));
}

.node.outgoing {
    opacity: 0.18;
    filter: grayscale(100%) blur(0.4px);
}

.node.course-hidden {
    opacity: 0;
    pointer-events: none;
}

.node.faded {
    opacity: 0.15;
    filter: grayscale(100%) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.link.faded {
    opacity: 0.08;
    stroke-width: 1px;
}

.link.incoming-link {
    stroke: #2563eb;
    stroke-width: 2.4px;
    opacity: 0.85;
}

.link.outgoing-link {
    stroke: #94a3b8;
    opacity: 0.18;
}

.link.course-hidden {
    opacity: 0;
}

/* Tooltip (Simple one) */
.tooltip {
    position: absolute;
    text-align: center;
    padding: 10px 14px;
    font: 13px 'Segoe UI', sans-serif;
    background: #2c3e50;
    color: #fff;
    border: 0;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 300px;
    font-weight: 500;
}

/* CS Submenu Styles */
#cs-category-menu {
    margin-bottom: 10px;
}

.cs-submenu {
    margin-left: 15px;
    margin-top: 5px;
    margin-bottom: 10px;
    padding-left: 10px;
    border-left: 2px solid #ddd;
}

.submenu-btn {
    font-size: 0.85rem;
    padding: 6px 10px;
    margin-left: 0;
    margin-bottom: 3px;
    background-color: #fafafa;
}

.submenu-btn:hover {
    background-color: #f0f0f0;
    border-color: #bbb;
}

.submenu-btn.active {
    background-color: #e3f2fd;
    color: #1976d2;
    border-color: #1976d2;
    font-weight: 500;
}

.cs-category-btn {
    position: relative;
}

.cs-category-btn.active {
    background-color: #007bff;
    color: white;
}

/* Multi-node display styles */
.multi-node-title {
    font-size: 1rem;
    margin-top: 15px;
    margin-bottom: 5px;
    color: #333;
    font-weight: 600;
}

.multi-node-level {
    font-size: 0.85rem;
    font-style: italic;
    color: #666;
    margin-top: 0;
    margin-bottom: 10px;
}

.node-separator {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 15px 0;
}

.no-rationale-message {
    color: #999;
    font-style: italic;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 4px;
}

/* Instructions overlay */
.instructions-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 24px;
    box-sizing: border-box;
}

.instructions-overlay.hidden {
    display: none;
}

.instructions-modal {
    width: min(680px, 100%);
    background: #ffffff;
    border-radius: 16px;
    padding: 32px 36px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.2);
    position: relative;
}

.instructions-close {
    position: absolute;
    top: 18px;
    right: 18px;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    line-height: 1;
}

.instructions-modal h2 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 1.6rem;
    color: #1f2937;
}

.instructions-tagline {
    margin-top: 0;
    margin-bottom: 20px;
    color: #4b5563;
    font-size: 0.95rem;
}

.instructions-steps {
    padding-left: 20px;
    margin-bottom: 24px;
    color: #374151;
    line-height: 1.6;
}

.instructions-steps li {
    margin-bottom: 12px;
}

.instructions-actions {
    display: flex;
    justify-content: flex-end;
}

.empty-state {
    margin-top: 40px;
    text-align: left;
}

.empty-state h3 {
    margin-top: 0;
    color: #1f2937;
}

.empty-state p {
    color: #4b5563;
    font-size: 0.9rem;
    line-height: 1.5;
}

.empty-state.hidden {
    display: none;
}

/* Utility */
.hidden {
    display: none;
}