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

:root {
  --sidebar-w: 280px;
  --color-bg: #0a0a0f;
  --color-surface: #12121a;
  --color-surface2: #1a1a26;
  --color-border: #2a2a3a;
  --color-text: #e0e0e8;
  --color-text-dim: #8888a0;
  --color-accent: #6c8cff;
  --color-accent2: #a78bfa;
  --color-accent-warm: #f0a050;
  --color-oral: #50c8a0;
  --color-math: #6c8cff;
  --color-bridge: #a78bfa;
  --font-sans: 'Noto Sans SC', 'Inter', system-ui, sans-serif;
  --font-serif: 'Noto Serif SC', 'Source Serif Pro', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 8px;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.8;
  overflow: hidden;
  height: 100vh;
}

/* === Layout === */
.app { display: flex; height: 100vh; }

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--color-border);
}

.logo { display: flex; flex-direction: column; gap: 4px; }
.logo-ds { font-size: 1.3rem; font-weight: 700; color: var(--color-accent); letter-spacing: 2px; }
.logo-en { font-size: 0.7rem; color: var(--color-text-dim); letter-spacing: 1px; text-transform: uppercase; }

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  text-decoration: none;
  color: var(--color-text-dim);
  transition: all 0.2s;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}

.nav-item:hover { color: var(--color-text); background: var(--color-surface2); }

.nav-item.active {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  background: rgba(108, 140, 255, 0.08);
}

.nav-num {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--color-text-dim);
  min-width: 20px;
}
.nav-item.active .nav-num { color: var(--color-accent); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
}

.lang-switcher { display: flex; gap: 4px; }
.lang-btn {
  flex: 1;
  padding: 6px 0;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-dim);
  font-size: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-sans);
}
.lang-btn:hover { border-color: var(--color-accent); color: var(--color-text); }
.lang-btn.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

/* === Mobile === */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.mobile-menu-btn span {
  width: 20px; height: 2px;
  background: var(--color-text);
  border-radius: 1px;
  transition: all 0.3s;
}

@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0 !important; }
}

/* === Content === */
.content {
  flex: 1;
  overflow-y: auto;
  height: 100vh;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.content-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 40px 80px;
}

/* === Chapter Styles === */
.chapter-header {
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--color-border);
}

.chapter-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--color-text), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chapter-subtitle {
  font-size: 1rem;
  color: var(--color-text-dim);
  font-style: italic;
}

/* Section blocks */
.section-block {
  margin-bottom: 36px;
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.section-label.oral {
  background: rgba(80, 200, 160, 0.12);
  color: var(--color-oral);
  border: 1px solid rgba(80, 200, 160, 0.25);
}

.section-label.math {
  background: rgba(108, 140, 255, 0.12);
  color: var(--color-math);
  border: 1px solid rgba(108, 140, 255, 0.25);
}

.section-label.bridge {
  background: rgba(167, 139, 250, 0.12);
  color: var(--color-bridge);
  border: 1px solid rgba(167, 139, 250, 0.25);
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--color-text);
}

.section-body p {
  margin-bottom: 14px;
  text-align: justify;
}

.section-body ul, .section-body ol {
  margin: 12px 0;
  padding-left: 24px;
}

.section-body li { margin-bottom: 8px; }

.section-body blockquote {
  border-left: 3px solid var(--color-accent);
  padding: 12px 20px;
  margin: 16px 0;
  background: var(--color-surface2);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--color-text-dim);
}

/* Math blocks */
.math-block {
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 16px 0;
  overflow-x: auto;
}

.math-block .katex-display {
  margin: 8px 0;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th {
  background: var(--color-surface2);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--color-accent);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

td {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(42, 42, 58, 0.5);
}

tr:hover td { background: rgba(108, 140, 255, 0.04); }

/* Bridge/Mapping boxes */
.bridge-box {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.06), rgba(108, 140, 255, 0.06));
  border: 1px solid rgba(167, 139, 250, 0.2);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 20px 0;
}

.bridge-box .bridge-title {
  font-weight: 600;
  color: var(--color-bridge);
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.mapping-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(167, 139, 250, 0.1);
  font-size: 0.9rem;
}

.mapping-row:last-child { border-bottom: none; }

.mapping-oral {
  color: var(--color-oral);
  min-width: 160px;
  font-weight: 500;
}

.mapping-arrow { color: var(--color-text-dim); font-size: 1.1rem; }
.mapping-math { color: var(--color-math); font-weight: 500; }

/* Chapter navigation */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

.chapter-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-accent);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: all 0.2s;
}

.chapter-nav a:hover {
  background: var(--color-surface2);
  border-color: var(--color-accent);
}

/* Intro page specific */
.intro-hero {
  text-align: center;
  padding: 60px 0 40px;
}

.intro-hero .hero-title {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.intro-hero .hero-sub {
  font-size: 1.1rem;
  color: var(--color-text-dim);
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.8;
}

.intro-overview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 32px 0;
}

.overview-card {
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.2s;
}

.overview-card:hover {
  border-color: var(--color-accent);
  transform: translateY(-2px);
}

.overview-card .card-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-accent);
  margin-bottom: 6px;
}

.overview-card .card-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.overview-card .card-desc {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  line-height: 1.6;
}

@media (max-width: 600px) {
  .intro-overview { grid-template-columns: 1fr; }
  .content-inner { padding: 32px 20px 60px; }
  .chapter-title { font-size: 1.6rem; }
  .intro-hero .hero-title { font-size: 2rem; }
}

/* KaTeX overrides */
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* Highlight */
.highlight { color: var(--color-accent); font-weight: 500; }
.highlight-warm { color: var(--color-accent-warm); font-weight: 500; }

/* Code */
code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--color-surface2);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--color-accent-warm);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-dim); }

/* Language toggle for bilingual */
/* Content area language switching */
.lang-zh .en-text { display: none; }
.lang-en .zh-text { display: none; }
.lang-bi .en-text, .lang-bi .zh-text { display: inline; }
.en-text { color: var(--color-text-dim); font-style: italic; }
.lang-bi .en-text { display: block; margin-top: 4px; font-size: 0.92em; }

/* Sidebar language switching */
.sidebar .zh-text,
.sidebar .en-text { display: none; }
.sidebar.lang-zh .zh-text { display: inline; }
.sidebar.lang-zh .en-text { display: none; }
.sidebar.lang-en .zh-text { display: none; }
.sidebar.lang-en .en-text { display: inline; }
.sidebar.lang-bi .zh-text { display: inline; }
.sidebar.lang-bi .en-text { display: inline; font-size: 0.85em; }

/* Sidebar nav title - hide non-active language titles */
.nav-item .nav-title { display: none; }
.sidebar.lang-zh .nav-item .nav-title.zh-text { display: inline; }
.sidebar.lang-en .nav-item .nav-title.en-text { display: inline; }
.sidebar.lang-bi .nav-item .nav-title.zh-text { display: inline; }
.sidebar.lang-bi .nav-item .nav-title.en-text { display: inline; font-size: 0.8em; color: var(--color-text-dim); margin-left: 4px; }

/* Logo language switching */
.sidebar.lang-zh .logo-ds { display: inline; }
.sidebar.lang-zh .logo-en { display: block; font-size: 0.7rem; }
.sidebar.lang-en .logo-ds { display: none; }
.sidebar.lang-en .logo-en { display: inline; font-size: 1.3rem; font-weight: 700; color: var(--color-accent); letter-spacing: 2px; text-transform: none; }
.sidebar.lang-bi .logo-ds { display: inline; }
.sidebar.lang-bi .logo-en { display: inline; font-size: 1.3rem; font-weight: 700; color: var(--color-accent); letter-spacing: 2px; text-transform: none; margin-left: 8px; }
