/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --bg-code: #0b1220;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-blue: #38bdf8;
  --accent-cyan: #22d3ee;
  --accent-orange: #fb923c;
  --accent-green: #4ade80;
  --accent-purple: #a78bfa;
  --accent-pink: #f472b6;
  --accent-yellow: #facc15;

  --border-color: #334155;
  --border-light: #475569;

  --code-keyword: #c084fc;
  --code-string: #4ade80;
  --code-number: #fbbf24;
  --code-comment: #64748b;
  --code-function: #60a5fa;
  --code-type: #22d3ee;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --sidebar-width: 320px;
  --header-height: 64px;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  width: 100%;
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ===== App Layout ===== */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Header ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--text-primary);
}

.header-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  color: var(--bg-primary);
}

.header-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header-title-sub {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 40px;
  flex: 1;
}

.header-nav-btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.header-nav-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.header-nav-btn.active {
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.3);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.header-stat-num {
  font-weight: 600;
  color: var(--accent-orange);
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0;
  transition: transform 0.3s ease;
  z-index: 90;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

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

.sidebar-module-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.sidebar-module-header:hover {
  background: var(--bg-hover);
}

.module-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.module-icon.m0 { background: linear-gradient(135deg, #38bdf8, #22d3ee); color: #0f172a; }
.module-icon.m1 { background: linear-gradient(135deg, #fb923c, #fbbf24); color: #0f172a; }
.module-icon.m2 { background: linear-gradient(135deg, #4ade80, #22d3ee); color: #0f172a; }
.module-icon.m3 { background: linear-gradient(135deg, #a78bfa, #f472b6); color: #0f172a; }
.module-icon.m4 { background: linear-gradient(135deg, #f472b6, #fb923c); color: #0f172a; }

.module-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.module-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  font-size: 12px;
}

.module-chevron.expanded {
  transform: rotate(90deg);
}

.module-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.module-children.expanded {
  max-height: 2000px;
}

.topic-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 54px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
  position: relative;
}

.topic-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.topic-item.active {
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.08);
  border-left-color: var(--accent-blue);
}

.topic-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.topic-item.active .topic-dot {
  background: var(--accent-blue);
  box-shadow: 0 0 8px var(--accent-blue);
}

.topic-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  margin-left: auto;
}

.topic-item.active .topic-badge {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-blue);
}

/* ===== Main Content ===== */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  flex: 1;
  overflow-y: auto;
  padding: 0;
  transition: margin-left 0.3s ease;
}

.main-content.sidebar-collapsed {
  margin-left: 0;
}

/* ===== Hero Section ===== */
.hero-section {
  position: relative;
  padding: 60px 48px 48px;
  overflow: hidden;
}

.hero-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at top right, rgba(56, 189, 248, 0.15), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(251, 146, 60, 0.1), transparent 50%);
  pointer-events: none;
}

.hero-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(56, 189, 248, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 20px;
  font-size: 12px;
  color: var(--accent-blue);
  margin-bottom: 16px;
}

.hero-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 42px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #f1f5f9 0%, #38bdf8 50%, #22d3ee 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 640px;
  line-height: 1.7;
}

.hero-stats {
  display: flex;
  gap: 40px;
  margin-top: 32px;
}

.hero-stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-stat-num {
  font-family: 'Noto Serif SC', serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-orange);
}

.hero-stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Module Overview Cards ===== */
.modules-section {
  padding: 0 48px 48px;
}

.section-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-title-line {
  width: 4px;
  height: 24px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent-blue), var(--accent-cyan));
}

.module-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.module-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent, var(--accent-blue));
  opacity: 0;
  transition: opacity 0.25s ease;
}

.module-card:hover {
  border-color: var(--card-accent, var(--accent-blue));
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.module-card:hover::before {
  opacity: 1;
}

.module-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.module-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.module-card-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 18px;
  font-weight: 700;
}

.module-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.module-card-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.module-card-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Content Panel (Topic Detail) ===== */
.content-panel {
  padding: 40px 48px 80px;
  max-width: 1100px;
}

.content-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.content-breadcrumb-link {
  color: var(--accent-blue);
  cursor: pointer;
  transition: opacity 0.2s;
}

.content-breadcrumb-link:hover {
  opacity: 0.8;
}

.content-breadcrumb-sep {
  color: var(--text-muted);
}

.content-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
}

.content-module-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 12px;
  margin-bottom: 28px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-blue);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

/* ===== Content Sections ===== */
.content-section {
  margin-bottom: 36px;
}

.content-section-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
  padding-left: 14px;
  border-left: 3px solid var(--accent-blue);
  color: var(--text-primary);
}

.content-section p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.8;
}

.content-section ul,
.content-section ol {
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding-left: 24px;
  line-height: 1.8;
}

.content-section li {
  margin-bottom: 6px;
}

.content-section strong {
  color: var(--text-primary);
  font-weight: 600;
}

.content-section em {
  color: var(--accent-orange);
  font-style: normal;
  font-weight: 500;
}

/* ===== Formula Block ===== */
.formula-block {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-orange);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 16px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  color: var(--accent-orange);
  overflow-x: auto;
}

.formula-block .formula-label {
  display: block;
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

/* ===== Tip / Note Box ===== */
.tip-box {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 16px 0;
  display: flex;
  gap: 12px;
}

.tip-box-icon {
  flex-shrink: 0;
  font-size: 18px;
  color: var(--accent-blue);
}

.tip-box-content {
  flex: 1;
}

.tip-box-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-blue);
  margin-bottom: 4px;
}

.tip-box-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ===== Code Block ===== */
.code-block-container {
  margin: 16px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: var(--bg-code);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.code-block-lang {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.code-block-copy {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.code-block-copy:hover {
  background: var(--accent-blue);
  color: var(--bg-primary);
}

.code-block-pre {
  margin: 0;
  padding: 16px 20px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.7;
}

.code-block-pre code {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
}

/* Syntax highlighting */
.tok-keyword { color: var(--code-keyword); font-weight: 500; }
.tok-type { color: var(--code-type); }
.tok-function { color: var(--code-function); }
.tok-string { color: var(--code-string); }
.tok-number { color: var(--code-number); }
.tok-comment { color: var(--code-comment); font-style: italic; }
.tok-operator { color: var(--text-secondary); }
.tok-preprocessor { color: var(--accent-orange); }
.tok-punctuation { color: var(--text-muted); }

/* Inline code */
.inline-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 2px 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--accent-cyan);
}

/* ===== Truth Table ===== */
.truth-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}

.truth-table th,
.truth-table td {
  padding: 10px 16px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.truth-table th {
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: 600;
}

.truth-table td {
  color: var(--text-secondary);
}

.truth-table .result-col {
  background: rgba(56, 189, 248, 0.08);
  color: var(--accent-blue);
  font-weight: 500;
}

/* ===== Progress Tracker ===== */
.progress-tracker {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  min-width: 200px;
}

.progress-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

.progress-percent {
  color: var(--accent-blue);
  font-weight: 600;
}

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

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Knowledge Map ===== */
.knowledge-map-section {
  padding: 40px 48px 60px;
}

.map-container {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px;
  min-height: 500px;
  overflow: auto;
}

.map-center-node {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 40px auto;
  width: 200px;
  height: 80px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  border-radius: 16px;
  font-family: 'Noto Serif SC', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--bg-primary);
  box-shadow: 0 0 40px rgba(56, 189, 248, 0.4);
  z-index: 2;
}

.map-modules {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 24px;
  margin-top: 40px;
}

.map-module-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.2s;
}

.map-module-node:hover {
  transform: translateY(-4px);
}

.map-module-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--bg-primary);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.2s;
}

.map-module-node:hover .map-module-circle {
  box-shadow: 0 8px 30px var(--map-color, var(--accent-blue));
}

.map-module-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.map-module-count {
  font-size: 11px;
  color: var(--text-muted);
}

.map-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.map-lines svg {
  width: 100%;
  height: 100%;
}

/* ===== Subtopic expand list ===== */
.subtopic-list {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 16px 0;
}

.subtopic-item {
  border-bottom: 1px solid var(--border-color);
}

.subtopic-item:last-child {
  border-bottom: none;
}

.subtopic-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.subtopic-header:hover {
  background: var(--bg-hover);
}

.subtopic-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-blue);
  flex-shrink: 0;
}

.subtopic-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.subtopic-toggle {
  color: var(--text-muted);
  font-size: 14px;
  transition: transform 0.2s;
}

.subtopic-toggle.expanded {
  transform: rotate(180deg);
}

.subtopic-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 20px;
}

.subtopic-body.expanded {
  max-height: 5000px;
  padding: 0 20px 18px 40px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .hero-section {
    padding: 32px 20px;
  }

  .hero-title {
    font-size: 28px;
  }

  .hero-stats {
    flex-wrap: wrap;
    gap: 20px;
  }

  .modules-section {
    padding: 0 20px 32px;
  }

  .content-panel {
    padding: 24px 20px 60px;
  }

  .content-title {
    font-size: 24px;
  }

  .knowledge-map-section {
    padding: 24px 20px;
  }

  .map-container {
    padding: 20px;
  }

  .map-modules {
    gap: 16px;
  }

  .map-module-circle {
    width: 72px;
    height: 72px;
    font-size: 18px;
  }

  .header-nav {
    display: none;
  }

  .header-stat {
    display: none;
  }

  .progress-tracker {
    bottom: 12px;
    right: 12px;
    padding: 10px 14px;
    min-width: 140px;
  }

  .sidebar-mobile-overlay {
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0, 0, 0, 0.5);
    z-index: 85;
  }

  .mobile-menu-btn {
    display: flex !important;
  }
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  color: var(--text-secondary);
  margin-right: 12px;
}
