/* ========================================
   系统架构设计师教程 - 学习网站 (多文件版)
   优化移动端体验
   ======================================== */

:root {
  --primary: #4a90d9;
  --primary-dark: #3a7bc8;
  --primary-light: #eef4ff;
  --accent: #f39c12;
  --accent-light: #fff8e1;
  --success: #27ae60;
  --success-light: #e8f5e9;
  --danger: #e74c3c;
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --text: #2c3e50;
  --text-secondary: #5a6a7a;
  --text-light: #8e99a4;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, object { max-width: 100%; height: auto; }

/* ---- Navbar ---- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar .logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.navbar .logo svg { width: 24px; height: 24px; flex-shrink: 0; }

.nav-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-right a {
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.nav-right a:hover { background: var(--primary-light); color: var(--primary); }
.nav-right a.active { background: var(--primary); color: white; }

/* ---- Mobile Menu ---- */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
}

@media (max-width: 640px) {
  .menu-toggle { display: block; }
  .nav-right {
    display: none;
    position: absolute;
    top: 56px;
    left: 0; right: 0;
    background: white;
    flex-direction: column;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  .nav-right.open { display: flex; }
  .nav-right a { width: 100%; padding: 10px 16px; }
}

/* ---- Hero (Homepage) ---- */
.hero {
  padding: 3rem 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
}

.hero h1 { font-size: clamp(1.5rem, 5vw, 2.5rem); font-weight: 800; margin-bottom: 0.8rem; }
.hero p { font-size: clamp(0.9rem, 3vw, 1.15rem); opacity: 0.9; max-width: 560px; margin: 0 auto 1.5rem; }

.hero .stats {
  display: flex;
  justify-content: center;
  gap: clamp(1.5rem, 5vw, 3rem);
  margin-top: 1.5rem;
}

.hero .stat-num { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800; }
.hero .stat-label { font-size: 0.8rem; opacity: 0.8; }

/* ---- Container ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

/* ---- Part Divider ---- */
.part-divider {
  text-align: center;
  padding: 2.5rem 0 0.8rem;
  position: relative;
}

.part-divider h2 {
  font-size: 1.3rem;
  color: var(--primary);
  display: inline-block;
  background: var(--bg);
  padding: 0 1.5rem;
  position: relative;
  z-index: 1;
}

.part-divider::before {
  content: '';
  position: absolute;
  top: 55%;
  left: 5%; right: 5%;
  height: 1px;
  background: var(--border);
}

/* ---- Chapter Grid ---- */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1rem 0;
}

.chapter-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.25s ease;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: block;
}

.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
  text-decoration: none;
}

.chapter-card:active { transform: translateY(-1px); }

.ch-number {
  position: absolute;
  top: -8px; right: 4px;
  font-size: 3.5rem;
  font-weight: 900;
  color: rgba(74,144,217,0.06);
  line-height: 1;
  pointer-events: none;
}

.ch-badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  margin-bottom: 0.6rem;
}

.chapter-card h3 {
  font-size: 1rem;
  margin-bottom: 0.4rem;
  color: var(--text);
  line-height: 1.4;
}

.ch-meta {
  font-size: 0.75rem;
  color: var(--text-light);
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

/* ---- Chapter Page Layout ---- */
.chapter-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem;
}

.chapter-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1.2rem;
  border-bottom: 2px solid var(--border);
}

.ch-label {
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
}

.chapter-header h1 {
  font-size: clamp(1.4rem, 4vw, 2rem);
  margin: 0.3rem 0 1rem;
  color: var(--text);
  line-height: 1.3;
}

/* ---- Mode Links ---- */
.mode-links {
  display: flex;
  gap: 0;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  width: fit-content;
  border: 1px solid var(--border);
}

.mode-link {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.25s;
  white-space: nowrap;
}

.mode-link:hover { background: white; text-decoration: none; }
.mode-link.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 6px rgba(74,144,217,0.25);
}

@media (max-width: 480px) {
  .mode-link { padding: 8px 14px; font-size: 0.8rem; }
}

/* ---- Reading Content ---- */
.reading-article, .fun-article {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: clamp(1.2rem, 4vw, 2.5rem);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  line-height: 2;
  word-break: break-word;
}

.reading-article h2, .fun-article h2 {
  font-size: clamp(1.2rem, 3.5vw, 1.5rem);
  color: var(--primary);
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--primary-light);
}

.reading-article h2:first-child, .fun-article h2:first-child { margin-top: 0; }

.reading-article h3 { font-size: clamp(1.05rem, 3vw, 1.25rem); margin: 2rem 0 0.8rem; }
.reading-article h4 { font-size: clamp(0.95rem, 2.8vw, 1.1rem); margin: 1.5rem 0 0.6rem; color: var(--text-secondary); }
.reading-article h5 { font-size: 1rem; margin: 1.2rem 0 0.5rem; color: var(--primary-dark); }

.reading-article p { margin-bottom: 0.8rem; text-align: justify; }
.reading-article ul, .reading-article ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.reading-article li { margin-bottom: 0.25rem; }
.reading-article strong { color: var(--primary-dark); }

.reading-article blockquote {
  border-left: 4px solid var(--primary);
  background: var(--primary-light);
  padding: 0.8rem 1.2rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
}

.reading-article pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 1.2rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 1rem 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}

.reading-article code {
  background: #f0f2f5;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.reading-article pre code { background: none; padding: 0; }

.reading-article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.85rem;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.reading-article thead { display: table; width: 100%; table-layout: fixed; }
.reading-article tbody { display: table; width: 100%; table-layout: fixed; }

.reading-article th {
  background: var(--primary);
  color: white;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.reading-article td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.reading-article tbody tr:hover { background: #f8faff; }

/* ---- SVG Figures ---- */
.figure-caption {
  text-align: center;
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.figure-svg, .inline-svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.caption-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* ---- Fun Content Styles ---- */
.story-section {
  margin-bottom: 2rem;
  scroll-margin-top: 70px;
}

.story-section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.story-intro {
  background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 100%);
  border-radius: var(--radius-sm);
  padding: 1.2rem 1.5rem;
  margin-bottom: 1.5rem;
  font-size: 1rem;
  line-height: 1.9;
  border-left: 4px solid var(--primary);
}

/* Dialogue */
.dialogue {
  margin: 1.5rem 0;
}

.dialogue-turn {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1rem;
  align-items: flex-start;
}

.dialogue-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: white;
  font-weight: 700;
}

.avatar-teacher { background: var(--primary); }
.avatar-student { background: var(--accent); }

.dialogue-bubble {
  flex: 1;
  padding: 0.8rem 1.2rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.7;
  min-width: 0;
}

.bubble-teacher {
  background: var(--primary-light);
  border-top-left-radius: 4px;
}

.bubble-student {
  background: var(--accent-light);
  border-top-right-radius: 4px;
}

.dialogue-name {
  font-weight: 600;
  font-size: 0.8rem;
  margin-bottom: 2px;
  color: var(--text-light);
}

/* Analogy Box */
.analogy-box {
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 1.2rem 1.5rem;
  margin: 1.5rem 0;
  border-left: 4px solid var(--accent);
  position: relative;
}

.analogy-box::before {
  content: '💡 类比';
  display: block;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

/* Key Point */
.key-point {
  background: var(--success-light);
  border-radius: var(--radius-sm);
  padding: 1.2rem 1.5rem;
  margin: 1.5rem 0;
  border-left: 4px solid var(--success);
}

.key-point::before {
  content: '🎯 考试重点';
  display: block;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.key-point ul { padding-left: 1.2rem; margin: 0.5rem 0 0; }
.key-point li { margin-bottom: 0.2rem; }

/* Memory Tip */
.memory-tip {
  background: #fce4ec;
  border-radius: var(--radius-sm);
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
  border-left: 4px solid var(--danger);
}

.memory-tip::before {
  content: '🧠 记忆口诀';
  display: block;
  font-weight: 700;
  color: var(--danger);
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.memory-tip .mnemonic {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  padding: 0.5rem;
  background: white;
  border-radius: 6px;
  margin: 0.5rem 0;
  letter-spacing: 2px;
}

/* Warning Box */
.warning-box {
  background: #fff3e0;
  border-radius: var(--radius-sm);
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
  border-left: 4px solid #ff9800;
}

.warning-box::before {
  content: '⚠️ 易错提醒';
  display: block;
  font-weight: 700;
  color: #ff9800;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

/* ---- Chapter Footer Nav ---- */
.chapter-footer-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 0.5rem;
}

.chapter-footer-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
  transition: all 0.2s;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-footer-nav a:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

.chapter-footer-nav .nav-center {
  flex-shrink: 0;
  max-width: none;
}

@media (max-width: 480px) {
  .chapter-footer-nav a { padding: 8px 12px; font-size: 0.78rem; }
}

/* ---- Progress Bar ---- */
.progress-bar {
  position: fixed;
  top: 56px;
  left: 0; right: 0;
  height: 3px;
  background: transparent;
  z-index: 99;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.15s;
}

/* ---- Back to Top ---- */
.back-top {
  position: fixed;
  bottom: 2rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-top.visible { opacity: 1; transform: translateY(0); }
.back-top:hover { background: var(--primary-dark); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .container { padding: 1rem; }
  .chapter-main { padding: 1rem; }
  .hero { padding: 2rem 1rem; }
  .chapter-grid { grid-template-columns: 1fr; gap: 0.8rem; }
  .chapter-card { padding: 1rem; }
  .reading-article, .fun-article { padding: 1rem; line-height: 1.8; }
  .reading-article h2, .fun-article h2 { margin-top: 1.8rem; }
  .dialogue-turn { gap: 0.5rem; }
  .dialogue-avatar { width: 32px; height: 32px; font-size: 0.9rem; }
  .dialogue-bubble { padding: 0.6rem 1rem; font-size: 0.9rem; }
}

@media (max-width: 380px) {
  .navbar { padding: 0 0.8rem; }
  .chapter-header h1 { font-size: 1.3rem; }
  .mode-link { padding: 6px 10px; font-size: 0.75rem; }
}

/* ---- Print ---- */
@media print {
  .navbar, .mode-links, .chapter-footer-nav, .back-top, .progress-bar { display: none !important; }
  .reading-article, .fun-article { box-shadow: none; border: none; padding: 0; }
  body { background: white; }
}

/* ---- Study Guide Components ---- */
.reading-article .exam-tip {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
}
.reading-article .exam-tip strong { color: var(--accent); }
.reading-article .exam-tip ul { margin-top: 0.5rem; margin-bottom: 0; }

.reading-article .formula-box {
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin: 1.2rem 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 0.92rem;
  line-height: 1.7;
  overflow-x: auto;
}
.reading-article .formula-box strong { color: var(--primary-dark); }
.reading-article .formula-box em { color: var(--text-secondary); font-size: 0.88rem; }

.reading-article .study-table { width: 100%; }

/* ---- Animations ---- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.chapter-card { animation: fadeInUp 0.4s ease backwards; }
.chapter-card:nth-child(1) { animation-delay: 0.02s; }
.chapter-card:nth-child(2) { animation-delay: 0.04s; }
.chapter-card:nth-child(3) { animation-delay: 0.06s; }
.chapter-card:nth-child(4) { animation-delay: 0.08s; }
.chapter-card:nth-child(5) { animation-delay: 0.1s; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b8c4; }

/* ---- Figure Gallery ---- */
.figure-gallery {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid var(--border);
}
.figure-gallery h2 {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.gallery-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}
.gallery-svg {
  max-width: 100%;
  height: auto;
  max-height: 200px;
}
@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: 1fr; }
}
