/* ================================================================
   Tutorial Page Styles — niuma_code
   教程阅读页 + 列表页样式，含暗色模式 CSS 变量覆盖
   ================================================================ */

/* ── CSS 变量（亮色主题） ─────────────────────────────── */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg-dark: #f4f6f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f4f8;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --gradient-primary: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --gradient-bg: radial-gradient(ellipse at top left, #e0ecff 0%, #f4f6f9 50%);
  --shadow-glow: 0 0 48px rgba(37, 99, 235, 0.06);
  --toc-width: 260px;
  --content-max-width: 820px;
}

/* ── 暗色主题 ────────────────────────────────────────── */
[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-dark: #93bbfd;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #283548;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --border: #334155;
  --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --gradient-bg: radial-gradient(ellipse at top left, #172554 0%, #0f172a 50%);
  --shadow-glow: 0 0 48px rgba(96, 165, 250, 0.08);
}

/* ── 全局重置 ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar（与主页一致） ─────────────────────────────── */
.navbar {
  position: fixed;
  top: 0; width: 100%;
  padding: 1rem 2rem;
  background: rgba(247, 248, 250, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 1000;
  transition: all 0.3s ease;
}
.navbar.scrolled {
  padding: 0.75rem 2rem;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .navbar {
  background: rgba(15, 23, 42, 0.88);
  border-bottom-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .navbar.scrolled {
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
}

.nav-container {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-logo {
  display: flex; align-items: center; gap: 0.75rem;
  text-decoration: none; font-weight: 700; font-size: 1.1rem;
  color: var(--text-primary);
}
.logo-icon {
  width: 32px; height: 32px;
  background: var(--gradient-primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 0.9rem;
}
.logo-text { color: var(--text-primary); }

.nav-links {
  display: flex; gap: 2rem; list-style: none; align-items: center;
}
.nav-links a {
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
  transition: color 0.3s ease;
}
.nav-links a:hover, .nav-links a.nav-active { color: var(--primary); text-decoration: none; }
.nav-links a.nav-active::after {
  content: ''; position: absolute; bottom: -4px; left: 0;
  width: 100%; height: 2px;
  background: var(--gradient-primary);
}
.nav-links a.nav-cta {
  background: var(--gradient-primary); color: #fff !important;
  padding: 0.5rem 1.25rem; border-radius: 8px;
}
.nav-links a.nav-cta:hover { opacity: 0.9; }

/* 语言下拉 */
.lang-dropdown-wrap { position: relative; }
.lang-dropdown-label { cursor: pointer; color: var(--text-secondary); font-size: 0.9rem; user-select: none; }
.lang-dropdown {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 0.5rem;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.5rem 0; min-width: 160px; list-style: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12); z-index: 2000;
}
.lang-dropdown-wrap.open .lang-dropdown { display: block; }
.lang-dropdown-item {
  display: block; padding: 0.5rem 1rem; font-size: 0.85rem;
  color: var(--text-secondary); transition: background 0.2s ease;
}
.lang-dropdown-item:hover, .lang-dropdown-item.active {
  background: var(--bg-card-hover); color: var(--primary);
}

/* 汉堡菜单 */
.hamburger {
  display: none; background: none; border: none; cursor: pointer;
  width: 24px; height: 20px; position: relative;
}
.hamburger span {
  display: block; position: absolute; left: 0; width: 100%; height: 2px;
  background: var(--text-primary); border-radius: 2px; transition: all 0.3s ease;
}
.hamburger span:nth-child(1) { top: 0; }
.hamburger span:nth-child(2) { top: 50%; transform: translateY(-50%); }
.hamburger span:nth-child(3) { bottom: 0; }
.hamburger.open span:nth-child(1) { top: 50%; transform: translateY(-50%) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { bottom: 50%; transform: translateY(50%) rotate(-45deg); }

@media (max-width: 768px) {
  .hamburger { display: block; }
  .nav-links {
    display: none; position: fixed; top: 60px; left: 0; right: 0;
    background: var(--bg-card); flex-direction: column;
    padding: 1rem; gap: 0; border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  }
  .nav-links.open { display: flex; }
  .nav-links .nav-link-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
  .nav-links .nav-link-item:last-child { border-bottom: none; }
}

/* ── 教程布局 ────────────────────────────────────────── */
.tutorial-layout {
  display: flex;
  max-width: 1280px;
  margin: 0 auto;
  padding-top: 80px;
  min-height: 100vh;
}

/* ── 目录侧边栏 ─────────────────────────────────────── */
.tutorial-toc {
  position: sticky;
  top: 80px;
  width: var(--toc-width);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 1.5rem 1rem 1.5rem 2rem;
  border-right: 1px solid var(--border);
  font-size: 0.85rem;
}
.tutorial-toc::-webkit-scrollbar { width: 3px; }
.tutorial-toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.toc-header {
  font-weight: 600; color: var(--text-primary); margin-bottom: 1rem;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em;
}

#tocNav a {
  display: block; padding: 0.35rem 0.75rem; margin-left: 0;
  color: var(--text-secondary); border-left: 2px solid transparent;
  transition: all 0.2s ease; text-decoration: none;
  border-radius: 0 4px 4px 0;
}
#tocNav a:hover { color: var(--primary); background: var(--bg-card-hover); text-decoration: none; }
#tocNav a.active {
  color: var(--primary); border-left-color: var(--primary);
  background: var(--bg-card-hover); font-weight: 500;
}
#tocNav a.toc-h3 { padding-left: 1.5rem; font-size: 0.82rem; }

@media (max-width: 1024px) {
  .tutorial-toc {
    position: fixed; top: 0; left: -300px; width: 280px;
    height: 100vh; max-height: none;
    background: var(--bg-card); z-index: 3000;
    transition: left 0.3s ease;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    padding-top: 80px;
  }
  .tutorial-toc.open { left: 0; }
}

/* ── 教程内容区 ─────────────────────────────────────── */
.tutorial-content {
  flex: 1;
  max-width: var(--content-max-width);
  padding: 2rem 3rem 6rem;
  min-width: 0;
}
@media (max-width: 768px) {
  .tutorial-content { padding: 1.5rem 1.25rem 4rem; }
}

/* ── Markdown 正文样式 ───────────────────────────────── */
.tutorial-content h1 {
  font-size: 2rem; font-weight: 700; margin-bottom: 1rem;
  color: var(--text-primary); line-height: 1.3;
}
.tutorial-content h2 {
  font-size: 1.4rem; font-weight: 600; margin-top: 2.5rem; margin-bottom: 0.75rem;
  padding-bottom: 0.4rem; border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.tutorial-content h3 {
  font-size: 1.15rem; font-weight: 600; margin-top: 1.8rem; margin-bottom: 0.5rem;
  color: var(--text-primary);
}
.tutorial-content h4 { font-size: 1rem; font-weight: 600; margin-top: 1.4rem; color: var(--text-primary); }

.tutorial-content p { margin-bottom: 1rem; color: var(--text-primary); }

.tutorial-content ul, .tutorial-content ol {
  margin-bottom: 1rem; padding-left: 1.5rem; color: var(--text-primary);
}
.tutorial-content li { margin-bottom: 0.4rem; }

.tutorial-content blockquote {
  border-left: 3px solid var(--primary);
  background: var(--bg-card-hover);
  padding: 0.75rem 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0;
  color: var(--text-secondary); font-style: italic;
}

.tutorial-content code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.88em; padding: 0.15em 0.4em;
  background: var(--bg-card-hover); border-radius: 4px; color: var(--primary);
}
.tutorial-content pre {
  background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem; margin: 1rem 0; overflow-x: auto;
}
.tutorial-content pre code {
  background: none; padding: 0; color: var(--text-primary); font-size: 0.85rem;
  line-height: 1.6;
}
[data-theme="dark"] .tutorial-content pre { background: #0d1117; border-color: #30363d; }
[data-theme="dark"] .tutorial-content pre code { color: #c9d1d9; }

.tutorial-content table {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
}
.tutorial-content th, .tutorial-content td {
  padding: 0.6rem 1rem; text-align: left;
  border: 1px solid var(--border);
}
.tutorial-content th {
  background: var(--bg-card-hover); font-weight: 600; font-size: 0.9rem;
}
.tutorial-content td { font-size: 0.9rem; }

.tutorial-content hr {
  border: none; border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ── 暗色模式按钮 ────────────────────────────────────── */
.theme-toggle {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; font-size: 1.2rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  transition: all 0.3s ease;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  transform: scale(1.05);
}

/* ── TOC 移动端切换按钮 ──────────────────────────────── */
.toc-toggle {
  display: none; position: fixed; bottom: 24px; left: 24px; z-index: 2000;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; font-size: 1.2rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  transition: all 0.3s ease;
  align-items: center; justify-content: center;
}
@media (max-width: 1024px) {
  .toc-toggle { display: flex; }
}

/* ── 教程列表页样式 ──────────────────────────────────── */
.tutorials-hero {
  text-align: center; padding: 120px 20px 60px;
}
.tutorials-hero h1 {
  font-size: 2.5rem; font-weight: 700; margin-bottom: 0.75rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tutorials-hero p {
  font-size: 1.1rem; color: var(--text-secondary); max-width: 600px; margin: 0 auto;
}

.tutorials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}
.tutorial-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: all 0.3s ease;
  text-decoration: none; color: inherit; display: block;
}
.tutorial-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 24px rgba(37, 99, 235, 0.08);
  transform: translateY(-2px); text-decoration: none;
}
.tutorial-card-order {
  font-size: 0.75rem; font-weight: 600;
  color: var(--primary); text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 0.5rem;
}
.tutorial-card h3 {
  font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem;
  color: var(--text-primary);
}
.tutorial-card p {
  font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.75rem;
}
.tutorial-card-tags {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.tutorial-card-tags span {
  font-size: 0.75rem; padding: 0.2rem 0.6rem;
  background: var(--bg-card-hover); border-radius: 4px;
  color: var(--text-secondary);
}

/* ── 上一篇 / 下一篇 导航 ──────────────────────────────── */
.tutorial-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: var(--content-max-width);
  margin: 3rem auto 0;
  padding: 1.5rem 3rem 0;
  border-top: 1px solid var(--border);
}
.tutorial-pager a {
  display: flex; flex-direction: column; gap: 0.35rem;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.25s ease;
  min-width: 0;
}
.tutorial-pager a:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.1);
  text-decoration: none;
}
.tutorial-pager .pager-prev {
  text-align: right;
  align-items: flex-end;
}
.tutorial-pager .pager-next {
  text-align: left;
  align-items: flex-start;
}
/* 边界场景（首/末篇）：只有一侧是链接时，链接项居中显示 */
.tutorial-pager > a:only-child {
  text-align: center;
  align-items: center;
}
.tutorial-pager .pager-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.tutorial-pager .pager-title {
  font-size: 0.95rem;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.tutorial-pager .pager-empty {
  /* 占位空槽，保持左右两栏对齐 */
  background: transparent;
  border: 1px dashed var(--border);
  pointer-events: none;
}
[data-theme="dark"] .tutorial-pager a {
  background: var(--bg-card);
}
@media (max-width: 768px) {
  .tutorial-pager {
    grid-template-columns: 1fr;
    padding: 1.5rem 1.25rem 0;
  }
  .tutorial-pager .pager-next {
    text-align: left;
    align-items: flex-start;
  }
  .tutorial-pager .pager-empty { display: none; }
}

/* ── 页脚 ────────────────────────────────────────────── */
.footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 2.5rem 2rem;
}
.footer-content {
  max-width: 1100px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.footer-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; color: var(--text-primary); }
.footer-license { font-size: 0.85rem; color: var(--text-secondary); }
.footer-meta { font-size: 0.8rem; color: var(--text-secondary); }
