/**
 * 专题页独立样式表
 * 供后端生成静态 HTML 使用
 * 路径: https://ai.aiyly.com/assets/topic.css
 */

/* ============ CSS 变量定义 ============ */
:root {
  /* 主色调 */
  --primary: #6366f1;
  --primary-hover: #4f46e5;

  /* 亮色主题（默认） */
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
}

/* 暗色主题 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border: #334155;
  }
}

/* 强制亮色主题 */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
}

/* 强制暗色主题 */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border: #334155;
}

/* ============ 基础重置 ============ */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica,
    Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--primary-hover);
}

/* ============ 通用容器 ============ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ============ 页面顶部导航栏 ============ */
.topic-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topic-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.topic-header .logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.topic-header .logo:hover {
  color: var(--primary-hover);
}

.topic-header .nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.topic-header .nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.2s ease;
}

.topic-header .nav-links a:hover {
  color: var(--primary);
}

/* ============ CTA 按钮 ============ */
.cta-button {
  display: inline-block;
  background: var(--primary);
  color: white !important;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.2s ease;
}

.cta-button:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* ============ Hero 区域 ============ */
.topic-hero {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  padding: 4rem 0;
  text-align: center;
}

.topic-hero h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 1rem 0;
  line-height: 1.3;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.topic-hero .summary {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin: 0 0 2rem 0;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

/* ============ 主内容区域 ============ */
.topic-content {
  padding: 3rem 0;
}

.topic-content .container {
  max-width: 800px;
}

.topic-content .cover-image {
  width: 100%;
  height: auto;
  border-radius: 12px;
  margin-bottom: 2rem;
  box-shadow: 0 4px 20px var(--shadow, rgba(0, 0, 0, 0.1));
}

.topic-content .content-body {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
}

/* 内容中的标题 */
.content-body h1,
.content-body h2,
.content-body h3,
.content-body h4,
.content-body h5,
.content-body h6 {
  color: var(--text);
  margin: 2rem 0 1rem 0;
  font-weight: 600;
  line-height: 1.4;
}

.content-body h1:first-child,
.content-body h2:first-child,
.content-body h3:first-child {
  margin-top: 0;
}

.content-body h1 { font-size: 1.75rem; }
.content-body h2 { font-size: 1.5rem; }
.content-body h3 { font-size: 1.25rem; }
.content-body h4 { font-size: 1.1rem; }
.content-body h5 { font-size: 1rem; }
.content-body h6 { font-size: 0.9rem; }

/* 段落 */
.content-body p {
  margin: 1rem 0;
}

.content-body p:first-child {
  margin-top: 0;
}

.content-body p:last-child {
  margin-bottom: 0;
}

/* 列表 */
.content-body ul,
.content-body ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.content-body li {
  margin: 0.5rem 0;
}

.content-body li > ul,
.content-body li > ol {
  margin: 0.25rem 0;
}

/* 图片 */
.content-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.5rem 0;
  display: block;
}

.content-body p > img {
  margin: 0;
}

/* 引用 */
.content-body blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-left: 4px solid var(--primary);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

.content-body blockquote p {
  margin: 0;
}

.content-body blockquote p + p {
  margin-top: 0.75rem;
}

/* 代码块 */
.content-body pre {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow-x: auto;
}

.content-body code {
  font-family: 'Monaco', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  font-size: 0.9em;
  background: var(--bg-secondary);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.content-body pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

/* 表格 */
.content-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.content-body th,
.content-body td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  text-align: left;
}

.content-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.content-body tr:nth-child(even) {
  background: var(--bg-secondary);
}

/* 分割线 */
.content-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* 强调 */
.content-body strong {
  font-weight: 600;
  color: var(--text);
}

.content-body em {
  font-style: italic;
}

.content-body mark {
  background: rgba(99, 102, 241, 0.2);
  padding: 0.1rem 0.2rem;
  border-radius: 2px;
}

/* ============ CTA 区域 ============ */
.topic-cta {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  padding: 4rem 0;
  text-align: center;
}

.topic-cta h2 {
  font-size: 2rem;
  font-weight: 700;
  color: white;
  margin: 0 0 1rem 0;
}

.topic-cta p {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 2rem 0;
}

.topic-cta .cta-button {
  background: white;
  color: var(--primary) !important;
  padding: 0.875rem 2rem;
  font-size: 1rem;
}

.topic-cta .cta-button:hover {
  background: var(--bg-secondary);
  transform: translateY(-2px);
}

/* ============ 页脚 ============ */
.topic-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  text-align: center;
}

.topic-footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.topic-footer .footer-links {
  margin-top: 0.5rem;
}

.topic-footer .footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
}

.topic-footer .footer-links a:hover {
  color: var(--primary);
}

/* ============ 响应式布局 ============ */
@media (max-width: 768px) {
  .topic-header .container {
    padding: 0 1rem;
  }

  .topic-header .nav-links {
    gap: 1rem;
  }

  .topic-header .nav-links a {
    font-size: 0.85rem;
  }

  .topic-hero {
    padding: 3rem 0;
  }

  .topic-hero h1 {
    font-size: 1.75rem;
  }

  .topic-hero .summary {
    font-size: 1rem;
  }

  .topic-content {
    padding: 2rem 0;
  }

  .topic-content .content-body {
    padding: 1.5rem;
    font-size: 0.95rem;
  }

  .content-body h1 { font-size: 1.5rem; }
  .content-body h2 { font-size: 1.3rem; }
  .content-body h3 { font-size: 1.15rem; }

  .content-body pre {
    padding: 0.75rem;
    font-size: 0.8rem;
  }

  .content-body table {
    font-size: 0.85rem;
  }

  .content-body th,
  .content-body td {
    padding: 0.5rem;
  }

  .topic-cta {
    padding: 3rem 0;
  }

  .topic-cta h2 {
    font-size: 1.5rem;
  }

  .topic-footer {
    padding: 1.5rem 0;
  }
}

@media (max-width: 480px) {
  .topic-header .logo {
    font-size: 1.25rem;
  }

  .topic-header .nav-links {
    gap: 0.75rem;
  }

  .topic-header .nav-links a:not(.cta-button) {
    display: none;
  }

  .topic-hero h1 {
    font-size: 1.5rem;
  }

  .topic-content .content-body {
    padding: 1rem;
  }

  .cta-button {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
}

/* ============ 相关文章区块 ============ */
.topic-related-articles {
  padding: 4rem 0;
  background: var(--bg-secondary);
}

.topic-related-articles h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 1.5rem 0;
  text-align: center;
}

.related-articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.related-article-card {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.related-article-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.related-article-card h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
}

.related-article-card h3 a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s ease;
}

.related-article-card h3 a:hover {
  color: var(--primary);
}

.related-article-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.back-to-home {
  display: inline-block;
  margin-top: 2rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.back-to-home:hover {
  color: var(--primary-hover);
}

/* 响应式 - 相关文章 */
@media (max-width: 768px) {
  .topic-related-articles {
    padding: 3rem 0;
  }

  .related-articles-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .related-article-card {
    padding: 1rem;
  }

  .related-article-card h3 {
    font-size: 1rem;
  }
}

/* ============ 打印样式 ============ */
@media print {
  .topic-header,
  .topic-cta,
  .topic-footer {
    display: none;
  }

  .topic-hero {
    padding: 1rem 0;
    background: none;
  }

  .topic-content {
    padding: 0;
  }

  .topic-content .content-body {
    border: none;
    padding: 0;
    box-shadow: none;
  }

  .content-body a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}
