/* ===== 全局变量与基础样式 ===== */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --cyan: #0891b2;
  --green: #22c55e;
  --green-dark: #166534;
  --orange: #f97316;
  --orange-dark: #92400e;
  --red: #ef4444;
  --gray: #64748b;
  --gray-light: #94a3b8;
  --gray-lighter: #e2e8f0;
  --bg: #f8fafc;
  --bg-alt: #f1f5f9;
  --text: #1e293b;
  --text-light: #475569;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --transition: 0.3s ease;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  font-size: 16px;
}

/* ===== 导航栏 ===== */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gray-lighter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 52px;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary);
}

.nav-links {
  display: flex;
  gap: 0.3rem;
}

.nav-links a {
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  transition: var(--transition);
}

.nav-links a:hover {
  background: var(--gray-lighter);
  color: var(--primary);
}

/* ===== 通用区块 ===== */
.section {
  padding: 4rem 1.5rem;
  min-height: 60vh;
}

.section-alt {
  background: var(--bg-alt);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
}

h2 {
  font-size: 1.75rem;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid var(--cyan);
  display: inline-block;
}

.key-point {
  background: #eff6ff;
  border-left: 4px solid var(--primary-light);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  color: var(--primary);
  font-weight: 500;
}

/* ===== 两栏布局 ===== */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
  align-items: start;
  margin-top: 1.5rem;
}

.col-text p {
  margin-bottom: 0.8rem;
}

.col-text ul {
  margin: 0.5rem 0 1rem 1.2rem;
}

.col-text li {
  margin-bottom: 0.4rem;
}

.col-visual {
  position: sticky;
  top: 70px;
}

/* ===== Hero 区 ===== */
.hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  color: white;
  text-align: center;
  padding-top: 52px;
}

.hero-content {
  max-width: 600px;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  line-height: 1.3;
}

.hero-sub {
  font-size: 1.15rem;
  opacity: 0.85;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.hero-objectives {
  text-align: left;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
  margin-bottom: 2rem;
}

.hero-objectives p {
  margin-bottom: 0.5rem;
  font-weight: 600;
  opacity: 0.9;
}

.hero-objectives ul {
  list-style: none;
  padding: 0;
}

.hero-objectives li {
  padding: 0.25rem 0;
  opacity: 0.85;
}

.hero-objectives li::before {
  content: "✓ ";
  color: var(--green);
  font-weight: bold;
}

/* ===== 按钮 ===== */
.btn-primary {
  background: var(--primary-light);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary-light);
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--primary-light);
  color: white;
}

/* ===== 信息卡片 ===== */
.info-card {
  background: white;
  border: 1px solid var(--gray-lighter);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}

.info-card h3 {
  font-size: 0.95rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.info-card ul {
  margin: 0.3rem 0 0 1rem;
}

/* ===== 存储层级图 ===== */
.memory-hierarchy {
  background: white;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.memory-hierarchy h3 {
  text-align: center;
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.hierarchy-bar {
  padding: 0.6rem 1rem;
  margin: 0.4rem auto;
  border-radius: var(--radius);
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  transition: var(--transition);
}

.hierarchy-bar.active {
  box-shadow: 0 0 0 3px rgba(8,145,178,0.3);
  transform: scale(1.03);
}

.hint {
  font-size: 0.82rem;
  color: var(--gray);
  text-align: center;
  margin-top: 0.8rem;
}

/* ===== 反相器动画区 ===== */
.latch-demo {
  background: white;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.status-text {
  font-size: 0.9rem;
  color: var(--green-dark);
  font-weight: 600;
  margin-top: 0.5rem;
}

/* ===== 信号图例 ===== */
.signal-legend {
  margin-top: 1rem;
}

.signal-legend h3 {
  font-size: 0.95rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== 6T 结构图 ===== */
.cell-diagram-wrapper {
  background: white;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.demo-svg-wrap {
  border: 2px solid var(--gray-lighter);
}

/* ===== 动态演示区 ===== */
.demo-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}

.btn-mode {
  background: white;
  border: 2px solid var(--gray-light);
  padding: 0.5rem 1.2rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  color: var(--text-light);
  transition: var(--transition);
}

.btn-mode:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.btn-mode.active {
  background: var(--primary-light);
  color: white;
  border-color: var(--primary-light);
}

.btn-mode.btn-write.active {
  background: var(--orange);
  border-color: var(--orange);
}

.btn-mode.active-read {
  background: var(--cyan);
  color: white;
  border-color: var(--cyan);
}

.btn-mode.active-hold {
  background: var(--gray);
  color: white;
  border-color: var(--gray);
}

.demo-explain {
  background: white;
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  min-height: 80px;
}

.demo-explain h3 {
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 0.4rem;
}

.demo-explain p {
  font-size: 0.9rem;
  color: var(--text-light);
  line-height: 1.6;
}

.demo-steps {
  margin-top: 0.5rem;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  opacity: 0.4;
  transition: opacity 0.4s ease;
}

.step.active {
  opacity: 1;
}

.step-num {
  background: var(--primary-light);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step.active .step-num {
  background: var(--green);
}

.step-text {
  font-size: 0.88rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* ===== 对比表格 ===== */
.compare-table-wrap {
  overflow-x: auto;
}

.compare-table {
  width: 100%;
  max-width: 800px;
  margin: 1rem auto 0;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.compare-table th,
.compare-table td {
  padding: 0.75rem 1.2rem;
  text-align: left;
  font-size: 0.9rem;
}

.compare-table th {
  background: var(--primary);
  color: white;
  font-weight: 600;
}

.compare-table tr:nth-child(even) {
  background: var(--bg-alt);
}

.compare-table td:first-child {
  font-weight: 600;
  color: var(--text);
}

.tag-green {
  background: #dcfce7;
  color: var(--green-dark);
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
}

.tag-orange {
  background: #fef3c7;
  color: var(--orange-dark);
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
}

/* ===== 术语卡片 ===== */
.term-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.term-card {
  background: white;
  border: 2px solid var(--gray-lighter);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: var(--transition);
  perspective: 600px;
  position: relative;
  min-height: 80px;
}

.term-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-lg);
}

.term-card .term-name {
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.term-card .term-desc {
  font-size: 0.85rem;
  color: var(--text-light);
  display: none;
}

.term-card.flipped .term-desc {
  display: block;
}

.term-card .term-hint {
  font-size: 0.75rem;
  color: var(--gray-light);
}

.term-card.flipped .term-hint {
  display: none;
}

/* ===== 测验 ===== */
.quiz-item {
  background: white;
  border: 1px solid var(--gray-lighter);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.quiz-item p {
  font-weight: 600;
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.quiz-opt {
  background: var(--bg-alt);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
  text-align: left;
  width: 100%;
}

.quiz-opt:hover:not(.disabled) {
  border-color: var(--primary-light);
  background: #eff6ff;
}

.quiz-opt.correct {
  background: #dcfce7;
  border-color: var(--green);
  color: var(--green-dark);
}

.quiz-opt.wrong {
  background: #fef2f2;
  border-color: var(--red);
  color: #991b1b;
}

.quiz-opt.disabled {
  cursor: default;
  opacity: 0.7;
}

.quiz-explain {
  margin-top: 0.5rem;
  padding: 0.5rem 0.8rem;
  background: #eff6ff;
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-light);
  display: none;
}

.quiz-explain.show {
  display: block;
}

.quiz-result {
  text-align: center;
  margin-top: 1.5rem;
}

.quiz-result p {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

/* ===== 总结 ===== */
.summary-box {
  background: white;
  border: 2px solid var(--cyan);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow);
}

.summary-box ul {
  list-style: none;
  padding: 0;
}

.summary-box li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-lighter);
  font-size: 0.95rem;
  line-height: 1.6;
}

.summary-box li:last-child {
  border-bottom: none;
}

.summary-box li::before {
  content: "▸ ";
  color: var(--cyan);
  font-weight: bold;
}

/* ===== 页脚 ===== */
footer {
  text-align: center;
  padding: 2rem;
  font-size: 0.82rem;
  color: var(--gray);
  border-top: 1px solid var(--gray-lighter);
}

/* ===== SVG 动画辅助 ===== */
.highlight-green {
  fill: #dcfce7 !important;
  stroke: #22c55e !important;
}

.highlight-orange {
  fill: #fde68a !important;
  stroke: #f97316 !important;
}

.highlight-active {
  stroke: #22c55e !important;
  stroke-width: 3 !important;
}

.highlight-bl {
  stroke: #3b82f6 !important;
  stroke-width: 3 !important;
}

.highlight-wl {
  stroke: #f59e0b !important;
  stroke-width: 3.5 !important;
}

.node-glow {
  filter: drop-shadow(0 0 6px rgba(34,197,94,0.6));
}

.node-glow-red {
  filter: drop-shadow(0 0 6px rgba(239,68,68,0.6));
}

.node-glow-orange {
  filter: drop-shadow(0 0 6px rgba(249,115,22,0.6));
}

/* 电荷流动点 */
@keyframes chargeFlow {
  0% { offset-distance: 0%; opacity: 1; }
  100% { offset-distance: 100%; opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.pulse-anim {
  animation: pulse 1s ease-in-out infinite;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .two-col {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .col-visual {
    position: static;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .nav-links {
    display: none;
  }

  #navbar {
    justify-content: center;
  }

  .section {
    padding: 3rem 1rem;
  }

  .term-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 1.5rem;
  }

  .term-grid {
    grid-template-columns: 1fr;
  }

  .demo-controls {
    flex-direction: column;
  }

  .btn-mode {
    width: 100%;
    text-align: center;
  }
}
