<template>
  <div class="home">
    <header class="hero">
      <h1 class="hero-title">📚 算法分析与设计</h1>
      <p class="hero-subtitle">教学辅助平台 — 从基础到进阶的算法学习之旅</p>
      <p class="hero-desc">
        涵盖六大核心章节：复杂度分析、分治法、动态规划、贪心算法、回溯法、分支限界法
      </p>
      <div class="hero-actions">
        <router-link to="/chapter/ch1" class="btn-primary">开始学习 →</router-link>
        <a href="#chapters" class="btn-secondary">浏览章节</a>
      </div>
    </header>

    <section id="chapters" class="chapters-grid">
      <router-link
        v-for="ch in chapters"
        :key="ch.id"
        :to="`/chapter/${ch.id}`"
        class="chapter-card"
      >
        <div class="card-icon">{{ ch.icon }}</div>
        <h3 class="card-title">{{ ch.title.split('—')[0].trim() }}</h3>
        <p class="card-subtitle">{{ ch.subtitle }}</p>
        <p class="card-desc">{{ ch.description }}</p>
        <div class="card-topics">
          <span v-for="topic in ch.topics.slice(0, 3)" :key="topic" class="topic-tag">
            {{ topic }}
          </span>
          <span v-if="ch.topics.length > 3" class="topic-tag more">+{{ ch.topics.length - 3 }}</span>
        </div>
        <div class="card-footer">
          <span class="explore-link">查看详情 →</span>
        </div>
      </router-link>
    </section>

    <section class="features-section">
      <h2 class="section-title">平台功能</h2>
      <div class="features-grid">
        <div class="feature-card">
          <div class="feature-icon">📖</div>
          <h3>代码阅览</h3>
          <p>所有算法代码源文件在线展示，支持语法高亮与一键复制</p>
        </div>
        <div class="feature-card">
          <div class="feature-icon">📂</div>
          <h3>分类导航</h3>
          <p>按章节和子主题分类组织，快速定位所需算法示例</p>
        </div>
        <div class="feature-card">
          <div class="feature-icon">🔍</div>
          <h3>知识点梳理</h3>
          <p>每个章节的关键知识点和算法思想概览</p>
        </div>
        <div class="feature-card">
          <div class="feature-icon">💻</div>
          <h3>C语言实现</h3>
          <p>全部使用标准C语言实现，适合教学演示与实验</p>
        </div>
      </div>
    </section>

    <footer class="footer">
      <p>算法分析与设计 教学辅助平台</p>
    </footer>
  </div>
</template>

<script setup>
import { chapters } from '../data/chapters.js'
</script>

<style scoped>
.home {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

.hero {
  text-align: center;
  padding: 60px 20px 40px;
}

.hero-title {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.hero-subtitle {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.hero-desc {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 24px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-primary, .btn-secondary {
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--hover-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--active-bg);
}

.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin: 40px 0;
}

.chapter-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
}

.chapter-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  border-color: var(--primary-color);
}

.card-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--primary-color);
  margin-bottom: 10px;
  font-weight: 500;
}

.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 14px;
  flex: 1;
}

.card-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.topic-tag {
  font-size: 11px;
  background: var(--tag-bg);
  color: var(--text-secondary);
  padding: 3px 10px;
  border-radius: 12px;
}

.topic-tag.more {
  background: var(--active-bg);
  color: var(--primary-color);
}

.card-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

.explore-link {
  font-size: 13px;
  color: var(--primary-color);
  font-weight: 600;
}

.section-title {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.features-section {
  margin: 60px 0;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.feature-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
}

.feature-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.feature-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.feature-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.footer {
  text-align: center;
  padding: 40px 0;
  color: var(--text-tertiary);
  font-size: 13px;
  border-top: 1px solid var(--border-color);
  margin-top: 40px;
}
</style>
