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

/* Full-width glass top bar (CS / ME); ETS brand teal + cream text */
.app-top-bar {
    flex-shrink: 0;
    position: relative;
    z-index: 200;
    background: rgba(0, 62, 78, 0.88);
    -webkit-backdrop-filter: saturate(160%) blur(20px);
    backdrop-filter: saturate(160%) blur(20px);
    border-bottom: 1px solid rgba(245, 233, 214, 0.18);
    box-shadow: none;
}

.app-top-bar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 11px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    box-sizing: border-box;
}

.app-top-bar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

a.app-top-bar-brand {
    font-weight: 600;
    font-size: 0.95rem;
    color: #F5E9D6;
    text-decoration: none;
    letter-spacing: -0.028em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

a.app-top-bar-brand:hover {
    opacity: 0.88;
}

.app-top-bar-brand--current {
    font-weight: 600;
    font-size: 0.95rem;
    color: #F5E9D6;
    letter-spacing: -0.028em;
}

html.theme-dark .app-top-bar {
    background: rgba(0, 62, 78, 0.92);
    border-bottom-color: rgba(245, 233, 214, 0.2);
    box-shadow: none;
}

html.theme-dark a.app-top-bar-brand,
html.theme-dark .app-top-bar-brand--current {
    color: #F5E9D6;
}

html.theme-dark a.app-top-bar-brand:hover {
    opacity: 0.9;
}

.app-top-bar .theme-toggle,
.app-top-bar .instructions-button {
    border-color: rgba(245, 233, 214, 0.45);
    color: #F5E9D6;
    background-color: transparent;
}

.app-top-bar .theme-toggle:hover,
.app-top-bar .instructions-button:hover {
    background-color: rgba(245, 233, 214, 0.12);
    color: #F5E9D6;
}

html.theme-dark .app-top-bar .theme-toggle,
html.theme-dark .app-top-bar .instructions-button {
    border-color: rgba(245, 233, 214, 0.45);
    color: #F5E9D6;
}

html.theme-dark .app-top-bar .theme-toggle:hover,
html.theme-dark .app-top-bar .instructions-button:hover {
    background-color: rgba(245, 233, 214, 0.12);
    color: #F5E9D6;
}

html:has(body.app-with-topbar) {
    height: 100%;
    overflow: hidden;
}

body.app-with-topbar {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

body.app-with-topbar .container {
    flex: 1;
    min-height: 0;
    height: auto;
}

body.app-with-topbar .sidebar-left,
body.app-with-topbar .sidebar-right,
body.app-with-topbar .main-content {
    height: 100%;
    min-height: 0;
}

.sidebar-left {
    width: 260px;
    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: 450px;
    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;
    gap: 10px;
    flex-wrap: wrap;
}

.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

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

.theme-toggle,
.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;
}

.theme-toggle:hover,
.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;
}

/* CS topics without connections */
.cs-topic-button.cs-topic-no-connection {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f5f5f5;
    color: #9ca3af;
}

.cs-topic-button.cs-topic-no-connection:hover {
    background-color: #f5f5f5;
    border-color: #d1d5db;
    color: #9ca3af;
}

.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-topic-textbook-btn {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.12s ease, color 0.15s ease;
}

.calc-topic-textbook-btn:hover {
    background: rgba(37, 99, 235, 0.22);
}

.calc-topic-textbook-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.calc-topic-textbook-btn--empty {
    color: #9ca3af;
    background: rgba(148, 163, 184, 0.22);
}

.calc-topic-textbook-btn--empty:hover {
    background: rgba(148, 163, 184, 0.32);
}

/* Textbook icon matches green Calculus II pillars (same courseKey as .calc-pill--calculus-ii) */
.calc-topic-textbook-btn--calculus-ii {
    background: rgba(31, 122, 74, 0.15);
    color: #1f7a4a;
}

.calc-topic-textbook-btn--calculus-ii:hover {
    background: rgba(31, 122, 74, 0.28);
}

.calc-topic-textbook-btn--calculus-ii:focus-visible {
    outline-color: #1f7a4a;
}

.calc-topic-textbook-btn--calculus-ii.calc-topic-textbook-btn--empty {
    color: #6b9080;
    background: rgba(76, 175, 125, 0.2);
}

.calc-topic-textbook-btn--calculus-ii.calc-topic-textbook-btn--empty:hover {
    background: rgba(76, 175, 125, 0.32);
}

.calc-topic-textbook-icon {
    display: block;
}

.calc-book-tooltip {
    position: fixed;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    max-width: min(400px, calc(100vw - 24px));
    max-height: min(70vh, 480px);
    overflow-y: auto;
    padding: 12px 14px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    background: #ffffff;
    color: #1e293b;
    font-size: 0.8rem;
    line-height: 1.45;
    border: 1px solid #e2e8f0;
    transition: opacity 0.12s ease, visibility 0.12s ease;
    z-index: 10000;
}

.calc-book-tooltip.is-visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.calc-book-tooltip-section {
    margin-top: 10px;
}

.calc-book-tooltip-section:first-child {
    margin-top: 0;
}

.calc-book-tooltip-heading {
    font-weight: 600;
    margin-bottom: 4px;
    color: #0f172a;
}

.calc-book-tooltip-text {
    font-weight: 400;
    color: #334155;
}

.calc-book-tooltip-empty {
    font-style: italic;
    color: #64748b;
}

.calc-book-tooltip-buy {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    margin: 0 0 6px;
    color: #0369a1;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.calc-book-tooltip-buy:hover {
    color: #0c4a6e;
}

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

.precursor-message {
    font-size: 0.9rem;
    line-height: 1.45;
    color: #374151;
    margin-bottom: 8px;
}

.precursor-successor-list {
    margin: 0 0 12px;
    padding-left: 1.2rem;
    font-size: 0.88rem;
    line-height: 1.45;
    color: #1f2937;
}

.precursor-successor-list li {
    margin-bottom: 4px;
}

/* 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: 14px;
    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.cs-highlight .node-circle {
    stroke: #ff4d4f;
    stroke-width: 3px;
    filter: drop-shadow(0 0 12px rgba(255, 77, 79, 0.75));
}

/* Direct prerequisites of discipline-connected topics, but not in that set (calc I/II color reserved for connected). */
.node.prereq-only .node-circle {
    fill: #94a3b8;
    filter: none;
}

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

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

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

/* KaTeX MathML layer: hide visual duplicate text, keep only HTML rendering */
.katex .katex-mathml {
    display: none !important;
}

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

/* -------------------------------------------------------------------------- */
/* Dark theme (html.theme-dark) — shared by CS and MechE sites              */
/* -------------------------------------------------------------------------- */
html.theme-dark {
    color-scheme: dark;
}

html.theme-dark body,
html.theme-dark {
    background-color: #0d1117;
    color: #adbac7;
}

html.theme-dark h1,
html.theme-dark h2,
html.theme-dark h3,
html.theme-dark h4 {
    color: #e6edf3;
}

html.theme-dark .sidebar-left,
html.theme-dark .sidebar-right {
    background-color: #161b22;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.45);
}

html.theme-dark .sidebar-right {
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.45);
}

html.theme-dark .sidebar-section h3 {
    color: #8b949e;
}

html.theme-dark .theme-toggle,
html.theme-dark .instructions-button,
html.theme-dark .tertiary-btn {
    border-color: #7c9cff;
    color: #a8b9ff;
}

html.theme-dark .theme-toggle:hover,
html.theme-dark .instructions-button:hover,
html.theme-dark .tertiary-btn:hover {
    background-color: rgba(124, 156, 255, 0.12);
}

html.theme-dark .primary-btn {
    background-color: #4d6dff;
    border-color: #4d6dff;
    color: #fff;
}

html.theme-dark .main-subtitle,
html.theme-dark .course-selection-summary,
html.theme-dark .core-summary,
html.theme-dark .topic-label small {
    color: #8b949e;
}

html.theme-dark .chart-container {
    background-color: #21262d;
    border-color: #30363d;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

html.theme-dark .view-tabs {
    background-color: #30363d;
}

html.theme-dark .view-tab {
    color: #adbac7;
}

html.theme-dark .view-tab.active {
    background-color: #21262d;
    color: #f0f6fc;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

html.theme-dark .view-tab:not(.active):hover {
    color: #f0f6fc;
}

html.theme-dark .cs-selection-summary,
html.theme-dark .calc-filter {
    color: #adbac7;
}

html.theme-dark #connection-threshold-value {
    color: #f0f6fc;
}

html.theme-dark #calc-sort-mode {
    background-color: #21262d;
    border-color: #444c56;
    color: #adbac7;
}

html.theme-dark .calc-topic-row.active {
    background-color: rgba(77, 109, 255, 0.15);
    box-shadow: 0 0 0 2px rgba(77, 109, 255, 0.35);
}

html.theme-dark .calc-topic-textbook-btn {
    background: rgba(77, 109, 255, 0.15);
    color: #7c9cff;
}

html.theme-dark .calc-topic-textbook-btn:hover {
    background: rgba(77, 109, 255, 0.28);
}

html.theme-dark .calc-topic-textbook-btn:focus-visible {
    outline-color: #7c9cff;
}

html.theme-dark .calc-topic-textbook-btn--calculus-ii {
    background: rgba(76, 175, 125, 0.2);
    color: #6ee7a8;
}

html.theme-dark .calc-topic-textbook-btn--calculus-ii:hover {
    background: rgba(76, 175, 125, 0.34);
}

html.theme-dark .calc-topic-textbook-btn--calculus-ii:focus-visible {
    outline-color: #6ee7a8;
}

html.theme-dark .calc-topic-textbook-btn--empty {
    color: #6e7681;
    background: rgba(110, 118, 129, 0.25);
}

html.theme-dark .calc-topic-textbook-btn--empty:hover {
    background: rgba(110, 118, 129, 0.38);
}

html.theme-dark .calc-topic-textbook-btn--calculus-ii.calc-topic-textbook-btn--empty {
    color: #7a9e8e;
    background: rgba(76, 175, 125, 0.12);
}

html.theme-dark .calc-topic-textbook-btn--calculus-ii.calc-topic-textbook-btn--empty:hover {
    background: rgba(76, 175, 125, 0.24);
}

html.theme-dark .calc-book-tooltip {
    background: #21262d;
    color: #e6edf3;
    border-color: #444c56;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

html.theme-dark .calc-book-tooltip-heading {
    color: #f0f6fc;
}

html.theme-dark .calc-book-tooltip-buy {
    color: #58c4ff;
}

html.theme-dark .calc-book-tooltip-buy:hover {
    color: #93d8ff;
}

html.theme-dark .calc-book-tooltip-text {
    color: #adbac7;
}

html.theme-dark .calc-book-tooltip-empty {
    color: #8b949e;
}

html.theme-dark .calc-pill--no-rationale {
    background: linear-gradient(135deg, #30363d, #6e7681);
    color: #f0f6fc;
}

html.theme-dark .tree-course,
html.theme-dark .tree-core,
html.theme-dark .tree-topic,
html.theme-dark .cs-topic-button {
    background: #21262d;
    border-color: #444c56;
    color: #e6edf3;
}

html.theme-dark .cs-category-button {
    background: linear-gradient(135deg, #21262d 0%, #30363d 100%);
    border-color: #6e7681;
    color: #e6edf3;
}

html.theme-dark .cs-category-button:hover {
    background: linear-gradient(135deg, #30363d 0%, #3d444d 100%);
    border-color: #8b949e;
}

html.theme-dark .cs-category-name {
    color: #f0f6fc;
}

html.theme-dark .cs-topic-button {
    background: #1c2128;
    border-color: #444c56;
}

html.theme-dark .cs-topic-button:hover {
    background: #30363d;
    border-color: #6e7681;
}

html.theme-dark .cs-topic-button.active {
    background: rgba(77, 109, 255, 0.2);
    border-color: #7c9cff;
    color: #b6c7ff;
}

html.theme-dark .tree-core:hover:not(.disabled),
html.theme-dark .tree-topic:hover:not(.disabled) {
    border-color: #6e7681;
    background-color: #2d333b;
}

html.theme-dark .tree-course.active,
html.theme-dark .tree-core.active,
html.theme-dark .tree-topic.active {
    border-color: #7c9cff;
    background-color: rgba(77, 109, 255, 0.18);
    color: #dbe2ff;
}

html.theme-dark .tree-course.calculus-i {
    background: linear-gradient(135deg, #1a2f4a 0%, #1e3a5f 100%);
    border-color: #4a90c2;
    color: #a8d4f0;
}

html.theme-dark .tree-course.calculus-i:hover {
    background: linear-gradient(135deg, #1e3a5f 0%, #254a75 100%);
    border-color: #6ab0e0;
}

html.theme-dark .tree-course.calculus-ii {
    background: linear-gradient(135deg, #1a3d2e 0%, #1f4d3a 100%);
    border-color: #4caf7d;
    color: #b8f0d4;
}

html.theme-dark .tree-course.calculus-ii:hover {
    background: linear-gradient(135deg, #1f4d3a 0%, #256545 100%);
}

html.theme-dark .tree-core.disabled,
html.theme-dark .tree-topic.disabled,
html.theme-dark .tree-topic:disabled {
    background-color: #21262d;
    opacity: 0.45;
}

html.theme-dark .cs-topic-button.cs-topic-no-connection {
    background-color: #21262d;
    color: #6e7681;
}

html.theme-dark #rationale-level {
    color: #8b949e;
}

html.theme-dark #rationale-content h5 {
    color: #7cb8ff;
    border-bottom-color: #30363d;
}

html.theme-dark .rationale-item {
    background: #21262d;
    border-color: #30363d;
    color: #adbac7;
}

html.theme-dark .rationale-item strong {
    color: #e6edf3;
}

html.theme-dark .precursor-message {
    color: #adbac7;
}

html.theme-dark .precursor-successor-list {
    color: #e6edf3;
}

html.theme-dark .link {
    stroke: #6e7681;
    stroke-opacity: 0.55;
}

html.theme-dark .link:hover {
    stroke: #9aa4b2;
}

html.theme-dark .node-circle {
    stroke: #21262d;
}

html.theme-dark .node.prereq-only .node-circle {
    fill: #6b7280;
}

html.theme-dark .node-label {
    fill: #e6edf3;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

html.theme-dark .cs-submenu {
    border-left-color: #444c56;
}

html.theme-dark .submenu-btn {
    background-color: #21262d;
    border-color: #444c56;
    color: #adbac7;
}

html.theme-dark .submenu-btn:hover {
    background-color: #30363d;
}

html.theme-dark .submenu-btn.active {
    background-color: rgba(77, 109, 255, 0.2);
    color: #b6c7ff;
    border-color: #7c9cff;
}

html.theme-dark .multi-node-title {
    color: #e6edf3;
}

html.theme-dark .multi-node-level {
    color: #8b949e;
}

html.theme-dark .node-separator {
    border-top-color: #30363d;
}

html.theme-dark .no-rationale-message {
    color: #8b949e;
    background: #21262d;
}

html.theme-dark .instructions-modal {
    background: #21262d;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

html.theme-dark .instructions-modal h2 {
    color: #f0f6fc;
}

html.theme-dark .instructions-tagline,
html.theme-dark .instructions-steps {
    color: #adbac7;
}

html.theme-dark .instructions-close {
    color: #8b949e;
}

html.theme-dark .empty-state h3 {
    color: #e6edf3;
}

html.theme-dark .empty-state p {
    color: #adbac7;
}

html.theme-dark .katex {
    color: #e6edf3;
}

/* -------------------------------------------------------------------------- */
/* Landing (index.html): mesh background + glass header & cards               */
/* -------------------------------------------------------------------------- */
html:has(body.home-body) {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

body.home-body {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    background-color: #eceff3;
}

body.home-splash {
    background: linear-gradient(165deg, #dde6f0 0%, #e8edf4 35%, #e2ebf5 70%, #d8e4f2 100%);
    position: relative;
}

body.home-splash::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse 90% 65% at 12% 18%, rgba(125, 170, 255, 0.22), transparent 52%),
        radial-gradient(ellipse 70% 55% at 88% 72%, rgba(90, 200, 160, 0.16), transparent 48%),
        radial-gradient(ellipse 50% 40% at 75% 12%, rgba(180, 150, 255, 0.12), transparent 45%);
}

body.home-splash .app-top-bar--splash {
    position: relative;
    z-index: 2;
}

html.theme-dark body.home-body {
    background-color: #0d1117;
}

html.theme-dark body.home-splash {
    background: linear-gradient(165deg, #0d1117 0%, #161b22 42%, #10151c 100%);
}

html.theme-dark body.home-splash::before {
    background:
        radial-gradient(ellipse 85% 60% at 15% 20%, rgba(77, 109, 255, 0.16), transparent 52%),
        radial-gradient(ellipse 65% 50% at 85% 75%, rgba(56, 170, 120, 0.1), transparent 50%);
}

.app-top-bar--splash .app-top-bar-inner {
    max-width: 1100px;
}

.home-main {
    position: relative;
    z-index: 2;
    flex: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 40px 24px 56px;
    width: 100%;
    box-sizing: border-box;
}

.home-title {
    text-align: center;
    margin: 0 0 12px;
    font-size: 1.85rem;
    color: #111827;
}

.home-lead {
    text-align: center;
    max-width: 640px;
    margin: 0 auto 40px;
    font-size: 1rem;
    line-height: 1.65;
    color: #4b5563;
}

.home-lead strong {
    color: #1f2937;
    font-weight: 600;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    align-items: stretch;
}

.home-card {
    display: flex;
    flex-direction: column;
    padding: 28px 26px;
    border-radius: 20px;
    text-decoration: none;
    color: inherit;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.42);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    backdrop-filter: saturate(180%) blur(24px);
    box-shadow:
        0 8px 40px rgba(15, 35, 75, 0.1),
        0 1px 0 rgba(255, 255, 255, 0.65) inset;
    transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease, background 0.22s ease;
}

.home-card:hover {
    transform: translateY(-4px) scale(1.01);
    background: rgba(255, 255, 255, 0.58);
    border-color: rgba(255, 255, 255, 0.75);
    box-shadow:
        0 20px 50px rgba(15, 35, 75, 0.14),
        0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.home-card:focus {
    outline: 2px solid rgba(61, 90, 254, 0.55);
    outline-offset: 3px;
}

.home-card-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
    margin-bottom: 8px;
}

.home-card-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 12px;
    letter-spacing: -0.02em;
}

.home-card-desc {
    flex: 1;
    margin: 0 0 20px;
    font-size: 0.92rem;
    line-height: 1.55;
    color: #4b5563;
}

.home-card-cta {
    font-size: 0.9rem;
    font-weight: 600;
    color: #3d5afe;
    margin-top: auto;
}

.home-card--cs {
    border-top: 3px solid rgba(37, 99, 235, 0.92);
}

.home-card--cs:hover {
    border-top-color: #1d4ed8;
}

.home-card--cs .home-card-cta {
    color: #2563eb;
}

.home-card--me {
    border-top: 3px solid rgba(31, 122, 74, 0.92);
}

.home-card--me:hover {
    border-top-color: #16633b;
}

.home-card--me .home-card-cta {
    color: #1f7a4a;
}

html.theme-dark .home-title {
    color: #f0f6fc;
}

html.theme-dark .home-lead {
    color: #adbac7;
}

html.theme-dark .home-lead strong {
    color: #e6edf3;
}

html.theme-dark .home-card {
    background: rgba(30, 36, 44, 0.52);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow:
        0 12px 48px rgba(0, 0, 0, 0.45),
        0 1px 0 rgba(255, 255, 255, 0.08) inset;
}

html.theme-dark .home-card:hover {
    background: rgba(40, 48, 58, 0.62);
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow:
        0 22px 56px rgba(0, 0, 0, 0.55),
        0 1px 0 rgba(255, 255, 255, 0.1) inset;
}

html.theme-dark .home-card-label {
    color: #8b949e;
}

html.theme-dark .home-card-title {
    color: #f0f6fc;
}

html.theme-dark .home-card-desc {
    color: #adbac7;
}

html.theme-dark .home-card--cs {
    border-top-color: #7c9cff;
}

html.theme-dark .home-card--cs .home-card-cta {
    color: #a8b9ff;
}

html.theme-dark .home-card--me {
    border-top-color: #4caf7d;
}

html.theme-dark .home-card--me .home-card-cta {
    color: #7ddbac;
}

.home-card--sources {
    border-top: 3px solid rgba(100, 116, 139, 0.92);
}

.home-card--sources:hover {
    border-top-color: #475569;
}

.home-card--sources .home-card-cta {
    color: #475569;
}

html.theme-dark .home-card--sources {
    border-top-color: #94a3b8;
}

html.theme-dark .home-card--sources .home-card-cta {
    color: #cbd5e1;
}

/* Source materials page */
.sources-body .sources-main {
    position: relative;
    z-index: 2;
    flex: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 24px 56px;
    width: 100%;
    box-sizing: border-box;
}

body.site-page.sources-body .sources-main {
    flex: 1;
}

.sources-title {
    margin: 0 0 12px;
    font-size: 1.65rem;
    color: #111827;
    letter-spacing: -0.02em;
}

.sources-lead {
    margin: 0 0 28px;
    font-size: 0.98rem;
    line-height: 1.65;
    color: #4b5563;
}

.sources-section {
    margin-bottom: 28px;
    padding: 20px 22px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.42);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
    box-shadow: 0 6px 28px rgba(15, 35, 75, 0.08);
}

.sources-heading {
    margin: 0 0 10px;
    font-size: 1.1rem;
    color: #1f2937;
}

.sources-note {
    margin: 0 0 12px;
    font-size: 0.88rem;
    line-height: 1.5;
    color: #6b7280;
}

.sources-code {
    font-size: 0.85em;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(100, 116, 139, 0.12);
    color: #334155;
}

.sources-list {
    margin: 0;
    padding-left: 1.15rem;
    font-size: 0.92rem;
    line-height: 1.65;
    color: #374151;
}

.sources-list li {
    margin-bottom: 6px;
}

.sources-list a {
    color: #2563eb;
    font-weight: 500;
}

.sources-list a:hover {
    text-decoration: underline;
}

.sources-placeholder {
    color: #6b7280;
    font-style: italic;
}

.sources-back {
    margin: 8px 0 0;
    font-size: 0.92rem;
}

.sources-back a {
    color: #475569;
    font-weight: 500;
}

.sources-back a:hover {
    color: #2563eb;
}

html.theme-dark .sources-title {
    color: #f0f6fc;
}

html.theme-dark .sources-lead {
    color: #adbac7;
}

html.theme-dark .sources-section {
    background: rgba(30, 36, 44, 0.52);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

html.theme-dark .sources-heading {
    color: #e6edf3;
}

html.theme-dark .sources-note {
    color: #8b949e;
}

html.theme-dark .sources-code {
    background: rgba(139, 148, 158, 0.15);
    color: #adbac7;
}

html.theme-dark .sources-list {
    color: #adbac7;
}

html.theme-dark .sources-list a {
    color: #79b8ff;
}

html.theme-dark .sources-placeholder {
    color: #8b949e;
}

html.theme-dark .sources-back a {
    color: #adbac7;
}

html.theme-dark .sources-back a:hover {
    color: #79b8ff;
}

/* =============================================================================
   iOS native app (WKWebView): class `cce-ios-app` is injected at document start.
   Does not affect GitHub Pages or desktop browsers.
   Column layout must keep flex min-height:0 chain so chart + list panels get height.
   ============================================================================= */

/* Single document element: was mistakenly `html.cce-ios-app html:has(...)` (never matched). */
html.cce-ios-app:has(body.app-with-topbar) {
    height: 100%;
    overflow: hidden;
}

/* WKWebView: prefer 100vh; 100dvh can report incorrectly inside embedded web views. */
html.cce-ios-app body.app-with-topbar {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    margin: 0;
}

html.cce-ios-app body.app-with-topbar .container {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

html.cce-ios-app .sidebar-left,
html.cce-ios-app .sidebar-right {
    width: 100%;
    max-width: none;
    flex-shrink: 0;
    height: auto;
    max-height: none;
    box-shadow: none;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

html.cce-ios-app .sidebar-left {
    max-height: min(36vh, 340px);
    min-height: 120px;
    padding: 14px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

html.cce-ios-app .sidebar-right {
    max-height: min(34vh, 300px);
    min-height: 120px;
    padding: 14px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    order: 3;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-bottom: none;
}

html.cce-ios-app .main-content {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    height: auto;
    max-height: none;
    padding: 12px 14px;
    order: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

/* Native app: CS/ME use SwiftUI toolbar; hide in-page header only on explorer pages. */
html.cce-ios-app body.app-with-topbar .app-top-bar {
    display: none !important;
}

html.cce-ios-app .chart-container {
    flex: 1 1 0;
    min-height: 0;
    margin: 0;
    padding: 12px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Guarantee non-zero chart area if flex distribution yields 0 height (WKWebView). */
html.cce-ios-app #chart-panel {
    flex: 1 1 auto;
    min-height: clamp(200px, 36vh, 640px);
    position: relative;
}

html.cce-ios-app #chart-panel svg#chart {
    display: block;
    max-width: 100%;
}

/* List tab: scrollable pills region must have height when panel is visible */
html.cce-ios-app #calc-list-panel:not(.hidden) {
    flex: 1 1 auto;
    min-height: clamp(180px, 32vh, 560px);
}

html.cce-ios-app .view-tabs {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: stretch;
}

html.cce-ios-app .view-tab {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 8px;
    font-size: 0.78rem;
    line-height: 1.25;
}

html.cce-ios-app .cs-category-button,
html.cce-ios-app .cs-topic-button {
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
}

html.cce-ios-app .tree-course,
html.cce-ios-app .tree-core,
html.cce-ios-app .tree-topic {
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
}

html.cce-ios-app .main-header {
    flex-shrink: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

html.cce-ios-app .main-title-group h1 {
    font-size: 1.15rem;
}

html.cce-ios-app .main-subtitle {
    font-size: 0.82rem;
}

html.cce-ios-app .calc-list-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

html.cce-ios-app .instructions-modal {
    width: calc(100vw - 28px);
    max-width: 100%;
    max-height: min(88vh, 640px);
    margin: 16px;
    padding: 18px 16px 20px;
    box-sizing: border-box;
}

html.cce-ios-app body.sources-body,
html.cce-ios-app html:has(body.sources-body) {
    overflow-y: auto;
    height: auto;
}

html.cce-ios-app .sources-main {
    padding: 16px 18px 32px;
    max-width: none;
}

html.cce-ios-app .sources-section {
    padding: 16px;
}

html.theme-dark.cce-ios-app .sidebar-left,
html.theme-dark.cce-ios-app .sidebar-right {
    border-color: rgba(255, 255, 255, 0.1);
}

/* -------------------------------------------------------------------------- */
/* Site shell — brand: #003E4E (flat, no gradients on shell surfaces)           */
/* -------------------------------------------------------------------------- */
html:has(body.site-page),
html:has(body.site-landing) {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

body.site-page {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Override global body,html { height:100vh; overflow:hidden } so long pages scroll */
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
    background: #f5f6f8;
}

html.theme-dark body.site-page {
    background: #0d1117;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 300;
    background: #003E4E;
    color: #F5E9D6;
    border-bottom: 1px solid rgba(245, 233, 214, 0.2);
}

.site-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 22px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
    box-sizing: border-box;
}

.site-brand {
    font-weight: 600;
    font-size: 1rem;
    color: #F5E9D6;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.site-brand:hover {
    opacity: 0.88;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    justify-content: center;
    flex: 1 1 auto;
}

.site-nav__link {
    font-size: 0.82rem;
    font-weight: 500;
    color: rgba(245, 233, 214, 0.88);
    text-decoration: none;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
}

.site-nav__link:hover {
    color: #F5E9D6;
}

.site-nav__link--current {
    color: #F5E9D6;
    border-bottom-color: #F5E9D6;
    font-weight: 600;
}

.site-header-actions .theme-toggle {
    border-color: rgba(245, 233, 214, 0.45);
    color: #F5E9D6;
}

.site-header-actions .theme-toggle:hover {
    background: rgba(245, 233, 214, 0.12);
}

html.theme-dark .site-header {
    background: #003E4E;
    border-bottom-color: rgba(245, 233, 214, 0.2);
}

.site-hero {
    background: #003E4E;
    color: #F5E9D6;
    padding: 28px 22px;
    text-align: center;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    box-sizing: border-box;
}

.site-hero-inner {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.site-hero h1 {
    margin: 0 0 16px;
    font-size: clamp(1.45rem, 1.1rem + 2vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: #F5E9D6;
    text-align: center;
}

.site-hero-lead {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.7;
    color: rgba(245, 233, 214, 0.9);
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
}

/* Hero photography (flat brand overlay, no gradients) */
.site-hero--with-image {
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    min-height: min(52vh, 420px);
}

.site-hero--with-image::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 62, 78, 0.72);
    z-index: 0;
    pointer-events: none;
}

.site-hero--inner h1 {
    margin-bottom: 0;
}

.site-hero--with-image.site-hero--home {
    background-image: url("images/home.jpg");
}

.site-hero--with-image.site-hero--about {
    background-image: url("images/about.jpg");
}

.site-hero--with-image.site-hero--how-to-use {
    background-image: url("images/how-to-use.jpg");
}

.site-hero--with-image.site-hero--methods {
    background-image: url("images/methods.jpg");
}

.site-hero--with-image.site-hero--team {
    background-image: url("images/251793371_l.jpg");
}

.site-hero--with-image.site-hero--dissemination {
    background-image: url("images/dissemination.jpg");
}

.site-hero--with-image.site-hero--contact {
    background-image: url("images/contact.jpg");
}

.site-main {
    flex: 1;
    width: 100%;
    margin: 0 auto;
    padding: 40px 22px 48px;
    box-sizing: border-box;
}

.site-main--landing {
    max-width: 960px;
}

.site-section {
    margin-bottom: 40px;
}

.site-section:last-child {
    margin-bottom: 0;
}

.site-section h2 {
    text-align: left;
    margin: 0 0 16px;
    font-size: 1.35rem;
    color: #111827;
}

.site-section p {
    margin: 0 0 16px;
    font-size: 1rem;
    line-height: 1.7;
    color: #374151;
}

.site-section p:last-child {
    margin-bottom: 0;
}

.site-section--muted {
    background: rgba(255, 255, 255, 0.75);
    border-radius: 16px;
    padding: 28px 24px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

html.theme-dark .site-section h2 {
    color: #f0f6fc;
}

html.theme-dark .site-section p {
    color: #adbac7;
}

html.theme-dark .site-section--muted {
    background: rgba(22, 27, 34, 0.55);
    border-color: rgba(255, 255, 255, 0.08);
}

.site-text-link {
    font-weight: 600;
    color: #003E4E;
    text-decoration: none;
}

.site-text-link:hover {
    text-decoration: underline;
}

html.theme-dark .site-text-link {
    color: #8ec5d4;
}

.site-footer {
    margin-top: auto;
    padding: 32px 22px 40px;
    background: #EDE8E0;
    border-top: 1px solid rgba(0, 62, 78, 0.12);
}

html.theme-dark .site-footer {
    background: #1a2426;
    border-top-color: rgba(255, 255, 255, 0.08);
}

.site-footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
}

.site-partner-logos {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 32px 40px;
}

.site-partner-logos a {
    display: inline-block;
    line-height: 0;
    text-decoration: none;
}

.site-partner-logos img {
    width: auto;
    object-fit: contain;
    vertical-align: middle;
}

.site-partner-logo--primary img {
    height: 56px;
    max-width: 320px;
    filter: brightness(0);
}

html.theme-dark .site-partner-logo--primary img {
    filter: brightness(0) invert(1);
}

.site-partner-logo--sub img {
    height: 30px;
    max-width: 140px;
}

html.theme-dark .site-partner-logo--sub img {
    filter: brightness(1.08);
}

.site-footer-note {
    margin: 24px 0 0;
    font-size: 0.78rem;
    color: #5c6a6e;
}

html.theme-dark .site-footer-note {
    color: #9ebcbf;
}

.site-footer-license {
    margin: 12px 0 0;
    font-size: 0.72rem;
    line-height: 1.5;
    color: #5c6a6e;
    text-align: center;
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
}

.site-footer-link {
    color: #003E4E;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.site-footer-link:hover {
    color: #002630;
}

html.theme-dark .site-footer-license {
    color: #8b9fa3;
}

html.theme-dark .site-footer-link {
    color: #8ec5d4;
}

html.theme-dark .site-footer-link:hover {
    color: #b8dce6;
}

body.site-landing {
    background: #EDE8E0;
}

html.theme-dark body.site-landing {
    background: #1a2426;
}

.site-main--landing .home-grid {
    margin-top: 8px;
}

/* Home: two content blocks (flat, no gradients) */
.site-main--home {
    max-width: 100%;
    padding: 0;
}

.home-blocks {
    max-width: 1040px;
    margin: 0 auto;
    padding: 32px 22px 48px;
    box-sizing: border-box;
}

.home-block {
    margin-bottom: 28px;
}

.home-block:last-child {
    margin-bottom: 0;
}

.home-block--explore {
    padding: 36px 0 8px;
}

.home-block--explore h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #003E4E;
    margin: 0 0 12px;
    letter-spacing: -0.02em;
}

.home-block__lead {
    margin: 0 0 24px;
    font-size: 1rem;
    line-height: 1.65;
    color: #3d4f54;
    max-width: 52rem;
}

html.theme-dark .home-block--explore h2 {
    color: #b8e0eb;
}

html.theme-dark .home-block__lead {
    color: #c5d0d3;
}

.home-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    align-items: stretch;
}

.site-main--home .home-card {
    border-radius: 0;
    padding: 26px 24px;
    border: 1px solid rgba(0, 62, 78, 0.2);
    border-top: none;
    border-left: 4px solid #003E4E;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 62, 78, 0.06);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.site-main--home .home-card-image {
    width: calc(100% + 48px);
    height: 190px;
    object-fit: cover;
    margin: -26px -24px 16px;
    display: block;
}

.site-main--home .home-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 62, 78, 0.1);
    border-color: rgba(0, 62, 78, 0.28);
    background: #fff;
}

.site-main--home .home-card--cs {
    border-left-color: #003E4E;
    border-top: 1px solid rgba(0, 62, 78, 0.2);
}

.site-main--home .home-card--me {
    border-left-color: #2a6f7e;
    border-top: 1px solid rgba(0, 62, 78, 0.2);
}

.site-main--home .home-card--cs .home-card-cta {
    color: #003E4E;
}

.site-main--home .home-card--me .home-card-cta {
    color: #2a6f7e;
}

html.theme-dark .site-main--home .home-card {
    background: #243032;
    border-color: rgba(245, 233, 214, 0.12);
    border-left-color: #5a9daa;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

html.theme-dark .site-main--home .home-card--me {
    border-left-color: #7eb8c4;
}

html.theme-dark .site-main--home .home-card:hover {
    background: #2a383b;
    border-color: rgba(245, 233, 214, 0.18);
}

html.theme-dark .site-main--home .home-card-label {
    color: #9ebcbf;
}

html.theme-dark .site-main--home .home-card-title {
    color: #F5E9D6;
}

html.theme-dark .site-main--home .home-card-desc {
    color: #b8c9cc;
}

.home-block--why {
    background: #003E4E;
    color: #F5E9D6;
    border-radius: 0;
    padding: 28px 28px 32px;
    border: 1px solid rgba(245, 233, 214, 0.15);
}

.home-block--why h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: #F5E9D6;
    margin: 0 0 14px;
    text-align: left;
}

.home-block--why p {
    margin: 0 0 14px;
    font-size: 1rem;
    line-height: 1.65;
    color: rgba(245, 233, 214, 0.95);
}

.home-block--why p:last-child {
    margin-bottom: 0;
}

.home-block--why .site-text-link {
    color: #F5E9D6;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.home-block--why .site-text-link:hover {
    color: #F5E9D6;
    opacity: 0.95;
}

html.theme-dark .home-block--why {
    background: #003E4E;
    border-color: rgba(245, 233, 214, 0.2);
}

.site-prose {
    max-width: 720px;
}

.site-prose h1 {
    text-align: left;
    font-size: 1.75rem;
    margin: 0 0 16px;
    color: #111827;
}

.site-prose h2 {
    text-align: left;
    font-size: 1.2rem;
    margin: 32px 0 12px;
    color: #111827;
}

.site-prose h2:first-child {
    margin-top: 0;
}

.site-prose h3 {
    margin: 24px 0 10px;
    font-size: 1.05rem;
    color: #1f2937;
}

.site-prose p,
.site-prose li {
    font-size: 0.98rem;
    line-height: 1.7;
    color: #374151;
}

.site-prose ul {
    margin: 12px 0 16px;
    padding-left: 1.35rem;
}

.site-prose li + li {
    margin-top: 8px;
}

html.theme-dark .site-prose h1,
html.theme-dark .site-prose h2,
html.theme-dark .site-prose h3 {
    color: #f0f6fc;
}

html.theme-dark .site-prose p,
html.theme-dark .site-prose li {
    color: #adbac7;
}

.site-prose strong {
    color: #0f2f38;
    font-weight: 700;
}

html.theme-dark .site-prose strong {
    color: #e8f4f7;
}

.team-member {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 0.35rem 1.5rem;
    align-items: start;
    margin: 1.75rem 0 2.25rem;
}

.team-member:first-of-type {
    margin-top: 0.75rem;
}

.team-member__photo {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 62, 78, 0.12);
}

html.theme-dark .team-member__photo {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.team-member__body {
    min-width: 0;
}

.team-member__body h3 {
    margin-top: 0;
}

@media (max-width: 540px) {
    .team-member {
        grid-template-columns: 1fr;
    }

    .team-member__photo {
        justify-self: center;
    }
}

.site-prose .methods-sub {
    font-size: 1rem;
    margin: 20px 0 8px;
    color: #1f2937;
}

html.theme-dark .site-prose .methods-sub {
    color: #e6edf3;
}

.methods-link-placeholder {
    color: #003E4E;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: default;
    pointer-events: none;
    opacity: 0.92;
}

html.theme-dark .methods-link-placeholder {
    color: #8ec5d4;
}

.methods-note {
    font-size: 0.9rem;
    color: #6b7280;
    margin-bottom: 16px;
}

html.theme-dark .methods-note {
    color: #8b949e;
}

.methods-course-links {
    list-style: none;
    padding-left: 0;
    margin: 8px 0 20px;
}

.methods-course-links li {
    margin-top: 6px;
}

.app-top-bar-inner--stacked {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-top: 10px;
    padding-bottom: 10px;
}

.app-top-bar-row-site {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.site-nav--compact {
    flex: 1 1 100%;
    justify-content: flex-start;
    gap: 0 14px;
    padding-top: 10px;
    margin-top: 8px;
    border-top: 1px solid rgba(245, 233, 214, 0.15);
}

.site-nav--compact .site-nav__link {
    color: rgba(245, 233, 214, 0.88);
}

.site-nav--compact .site-nav__link:hover {
    color: #F5E9D6;
}

.site-nav--compact .site-nav__link--current {
    color: #F5E9D6;
    border-bottom-color: #F5E9D6;
}

html.theme-dark .site-nav--compact {
    border-top-color: rgba(245, 233, 214, 0.15);
}

html.theme-dark .site-nav--compact .site-nav__link {
    color: rgba(245, 233, 214, 0.88);
}

html.theme-dark .site-nav--compact .site-nav__link:hover {
    color: #F5E9D6;
}

html.theme-dark .site-nav--compact .site-nav__link--current {
    color: #F5E9D6;
    border-bottom-color: #F5E9D6;
}

/* -------------------------------------------------------------------------- */
/* Responsive (marketing pages + tool top bar)                                 */
/* -------------------------------------------------------------------------- */
@media (max-width: 720px) {
    .site-header-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .site-nav {
        justify-content: flex-start;
        gap: 8px 14px;
    }

    .site-header-actions {
        align-self: flex-end;
    }

    .site-hero--with-image {
        min-height: min(42vh, 300px);
    }

    .site-main {
        padding-left: 16px;
        padding-right: 16px;
    }

    .home-blocks {
        padding-left: 16px;
        padding-right: 16px;
    }

    .site-partner-logos {
        gap: 20px 28px;
    }

    .site-partner-logo--primary img {
        height: 48px;
        max-width: min(280px, 75vw);
    }

    .site-partner-logo--sub img {
        height: 26px;
        max-width: min(120px, 45vw);
    }
}

@media (max-width: 480px) {
    .site-hero h1 {
        font-size: clamp(1.15rem, 4.5vw + 0.4rem, 1.65rem);
    }

    .site-hero-lead {
        font-size: 0.95rem;
    }
}