/* ============================================================
   STM32 学习笔记 · 个人博客样式
   设计参考：Butterfly 风格，深色科技电路主题
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #24292f;
  --text-2: #6e7781;
  --border: #e6eaf0;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.08);
  --accent: #06b6d4;
  --code-bg: #0b1220;
  --code-text: #e2e8f0;
  --header-text: #ffffff;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 10px 30px -14px rgba(16, 24, 40, 0.16);
  --shadow-hover: 0 4px 12px rgba(16, 24, 40, 0.08), 0 18px 40px -18px rgba(16, 24, 40, 0.25);
  --radius: 14px;
  --nav-h: 62px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
          -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", Consolas, "Courier New", ui-monospace, monospace;
}

html[data-theme="dark"] {
  --bg: #0d1117;
  --card: #161b22;
  --text: #e6edf3;
  --text-2: #8b949e;
  --border: #2d333b;
  --primary: #58a6ff;
  --primary-soft: rgba(88, 166, 255, 0.12);
  --accent: #56d4dd;
  --code-bg: #0b1120;
  --code-text: #e6edf3;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 4px 14px rgba(0, 0, 0, 0.5);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 15.5px;
  transition: background 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

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

img { max-width: 100%; display: block; }

::selection { background: rgba(37, 99, 235, 0.2); }

/* 阅读进度条 */
#reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  z-index: 1000; border-radius: 0 2px 2px 0;
}

/* ---------- 导航栏 ---------- */
#nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 900;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  color: var(--header-text);
  transition: background 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
  max-width: 1240px; margin: 0 auto;
}
#nav.scrolled {
  background: var(--card); color: var(--text);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  border-radius: 0 0 12px 12px;
}
#nav.scrolled a { color: var(--text); }
#nav.scrolled a:hover { color: var(--primary); }

.nav-site-title { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.nav-site-title a { color: inherit; }
.nav-site-title a:hover { color: inherit; opacity: 0.9; }
.nav-site-title i { color: var(--accent); margin-right: 6px; font-style: normal; }

#menus { display: flex; align-items: center; gap: 4px; }
.menu-link {
  color: inherit; padding: 7px 13px; border-radius: 8px;
  font-size: 14.5px; font-weight: 500; position: relative;
}
.menu-link:hover { background: var(--primary-soft); }
.menu-link.active::after {
  content: ""; position: absolute; left: 13px; right: 13px; bottom: 2px;
  height: 2px; border-radius: 2px; background: var(--primary);
}
.nav-btn {
  background: none; border: none; cursor: pointer; color: inherit;
  width: 36px; height: 36px; border-radius: 9px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 16px;
}
.nav-btn:hover { background: var(--primary-soft); }
#toggle-menu { display: none; }

/* ---------- Hero 区 ---------- */
.hero {
  position: relative;
  background-size: cover; background-position: center 30%;
  background-color: #0b1f3a;
  display: flex; flex-direction: column;
}
.hero::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(7, 18, 38, 0.5) 0%, rgba(7, 18, 38, 0.62) 55%, var(--bg) 100%);
}
.hero--full { min-height: 78vh; justify-content: center; align-items: center; }
.hero--inner { min-height: 250px; justify-content: flex-end; padding-bottom: 42px; }

.hero-content { position: relative; text-align: center; color: #fff; padding: 0 20px; margin-top: 40px; }
#site-title {
  font-size: clamp(34px, 6vw, 58px); font-weight: 800; letter-spacing: 3px;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.35);
}
#site-subtitle {
  margin-top: 14px; font-size: clamp(15px, 2.2vw, 19px); color: rgba(255, 255, 255, 0.88);
  min-height: 28px; font-weight: 400; letter-spacing: 1px;
}
.hero-social { margin-top: 22px; display: flex; gap: 14px; justify-content: center; }
.hero-social a {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); backdrop-filter: blur(6px);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px;
}
.hero-social a:hover { background: var(--primary); transform: translateY(-2px); }

.scroll-down {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 22px; opacity: 0.85; animation: bounce 1.6s infinite;
}
@keyframes bounce { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, 8px); } }

.inner-page-title { position: relative; color: #fff; font-size: 30px; font-weight: 700; text-align: center; }

/* ---------- 主布局 ---------- */
.layout {
  max-width: 1200px; margin: 0 auto; padding: 26px 18px 60px;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 26px;
  align-items: start;
}
.content-inner { min-width: 0; }
.aside-content { display: flex; flex-direction: column; gap: 18px; position: sticky; top: calc(var(--nav-h) + 14px); }

/* ---------- 卡片组件 ---------- */
.card-widget {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card-widget + .card-widget { margin-top: 18px; }
.card-head {
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15.5px;
  margin-bottom: 14px; color: var(--text);
}
.card-head i { color: var(--primary); font-style: normal; }
.aside-content .card-widget .card-head { font-size: 15px; }

/* ---------- 首页文章卡片 ---------- */
.recent-post-item {
  display: flex; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  margin-bottom: 22px;
}
.recent-post-item:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.post-cover { flex: 0 0 42%; position: relative; overflow: hidden; }
.post-cover img {
  width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease;
}
.recent-post-item:hover .post-cover img { transform: scale(1.06); }
.recent-post-info { flex: 1; padding: 22px 26px; display: flex; flex-direction: column; justify-content: center; }
.article-title {
  font-size: 21px; font-weight: 700; color: var(--text); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.article-title:hover { color: var(--primary); }
.article-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 10px 0; color: var(--text-2); font-size: 13.5px; }
.article-meta a { color: var(--text-2); }
.article-meta a:hover { color: var(--primary); }
.meta-sep { opacity: 0.5; }
.post-cat {
  background: var(--primary-soft); color: var(--primary);
  padding: 1px 10px; border-radius: 20px; font-size: 12.5px;
}
.article-excerpt {
  color: var(--text-2); font-size: 14px; line-height: 1.8;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- 侧边栏组件 ---------- */
.author-card { text-align: center; }
.author-avatar {
  width: 92px; height: 92px; border-radius: 50%; margin: 0 auto 12px;
  border: 3px solid var(--primary); padding: 3px; background: var(--card);
}
.author-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.author-name { font-size: 19px; font-weight: 700; }
.author-desc { color: var(--text-2); font-size: 13px; margin: 6px 0 14px; }
.btn-follow {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; padding: 8px 22px; border-radius: 30px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 18px -6px rgba(37, 99, 235, 0.5);
}
.btn-follow:hover { color: #fff; opacity: 0.92; }
.site-data { display: flex; justify-content: space-around; margin-top: 16px; border-top: 1px dashed var(--border); padding-top: 14px; }
.site-data a { color: var(--text-2); font-size: 13px; }
.site-data a:hover { color: var(--primary); }
.site-data .num { display: block; font-size: 19px; font-weight: 700; color: var(--text); }

/* 最新文章 */
.aside-list-item { display: flex; gap: 12px; align-items: center; padding: 7px 0; }
.aside-list-item + .aside-list-item { border-top: 1px dashed var(--border); }
.aside-list-thumb { width: 56px; height: 40px; border-radius: 8px; overflow: hidden; flex: 0 0 56px; }
.aside-list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.aside-list-info { min-width: 0; }
.aside-list-title {
  font-size: 13.5px; color: var(--text); line-height: 1.45; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.aside-list-title:hover { color: var(--primary); }
.aside-list-date { font-size: 12px; color: var(--text-2); }

/* 分类 */
.cat-list-item { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; }
.cat-list-item + .cat-list-item { border-top: 1px dashed var(--border); }
.cat-list-link { color: var(--text); font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.cat-list-link:hover { color: var(--primary); }
.cat-list-count {
  background: var(--primary-soft); color: var(--primary);
  font-size: 12px; padding: 0 9px; border-radius: 20px; min-width: 28px; text-align: center;
}

/* 标签云 */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 9px; }
.tag-item {
  color: var(--text-2); background: var(--bg); border: 1px solid var(--border);
  padding: 3px 12px; border-radius: 20px; font-size: 13px; transition: all 0.2s;
}
.tag-item:hover { color: #fff; background: var(--primary); border-color: var(--primary); }

/* 网站信息 */
.webinfo-item { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; color: var(--text-2); }
.webinfo-item + .webinfo-item { border-top: 1px dashed var(--border); }
.webinfo-item b { color: var(--text); font-weight: 600; }

/* ---------- 文章页 ---------- */
.post-header {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 30px 34px; box-shadow: var(--shadow); margin-bottom: 22px;
}
.post-header h1 { font-size: 28px; line-height: 1.4; margin-bottom: 14px; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--text-2); font-size: 13.5px; }
.post-meta a { color: var(--primary); }
.post-tag { display: inline-block; background: var(--primary-soft); color: var(--primary); padding: 1px 10px; border-radius: 20px; font-size: 12.5px; }

.post-content {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 38px 42px; box-shadow: var(--shadow);
  font-size: 15.5px;
}
.post-content > :first-child { margin-top: 0; }

/* 正文排版 */
.post-content h1, .post-content h2, .post-content h3, .post-content h4 {
  margin-top: 1.7em; margin-bottom: 0.7em; line-height: 1.4; font-weight: 700; color: var(--text);
  scroll-margin-top: calc(var(--nav-h) + 16px);
}
.post-content h2 {
  font-size: 24px; padding-left: 14px; position: relative;
}
.post-content h2::before {
  content: ""; position: absolute; left: 0; top: 0.18em; bottom: 0.18em; width: 4px;
  border-radius: 4px; background: linear-gradient(180deg, var(--primary), var(--accent));
}
.post-content h3 { font-size: 19.5px; }
.post-content h4 { font-size: 17px; }
.post-content p { margin: 0.9em 0; }
.post-content ul, .post-content ol { margin: 0.9em 0; padding-left: 1.6em; }
.post-content li { margin: 0.3em 0; }
.post-content strong { color: var(--text); font-weight: 700; }
.post-content a { border-bottom: 1px solid transparent; }
.post-content a:hover { border-bottom-color: var(--accent); }

/* 行内代码 */
.post-content code:not(pre code) {
  font-family: var(--mono); font-size: 0.88em; background: var(--primary-soft);
  color: var(--primary); padding: 2px 7px; border-radius: 6px; word-break: break-word;
}
html[data-theme="dark"] .post-content code:not(pre code) { color: #79c0ff; }

/* 代码块 */
.post-content pre {
  background: var(--code-bg); color: var(--code-text); border-radius: 12px;
  padding: 18px 20px; overflow: auto; margin: 1.2em 0; font-size: 13.5px; line-height: 1.7;
  position: relative; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.post-content pre code { font-family: var(--mono); background: none; color: inherit; padding: 0; }
.code-lang {
  position: absolute; top: 10px; right: 14px; font-size: 11.5px; color: rgba(148, 163, 184, 0.6);
  text-transform: uppercase; letter-spacing: 0.5px; font-family: var(--mono);
}
.code-copy {
  position: absolute; top: 8px; right: 8px; background: rgba(255, 255, 255, 0.08);
  border: none; color: rgba(226, 232, 240, 0.8); border-radius: 6px; font-size: 12px;
  padding: 3px 10px; cursor: pointer; font-family: var(--font); opacity: 0; transition: opacity 0.2s;
}
.post-content pre:hover .code-copy { opacity: 1; }
.code-copy:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.post-content pre { padding-top: 32px; }

/* 表格 */
.post-content table {
  width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: 14px;
  border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
}
.post-content th, .post-content td { padding: 10px 14px; border: 1px solid var(--border); text-align: left; }
.post-content th { background: var(--primary-soft); color: var(--text); font-weight: 700; white-space: nowrap; }
.post-content tbody tr:nth-child(even) { background: var(--bg); }
.post-content tbody tr:hover { background: var(--primary-soft); }

/* 引用 */
.post-content blockquote {
  margin: 1.2em 0; padding: 12px 18px; border-left: 4px solid var(--primary);
  background: var(--primary-soft); border-radius: 0 10px 10px 0; color: var(--text-2);
}
.post-content blockquote p { margin: 0.3em 0; }

/* 分割线 */
.post-content hr { border: none; height: 1px; background: var(--border); margin: 2em 0; }

/* 任务清单 */
.post-content li.task-item { list-style: none; margin-left: -1.3em; }
.post-content li.task-item > p { margin: 0; display: inline; }
.post-content li.task-item input[type="checkbox"] {
  accent-color: var(--primary); margin-right: 8px; transform: translateY(1px);
}

/* 目录 */
.toc-list { list-style: none; max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.toc-list li { margin: 4px 0; }
.toc-list a { color: var(--text-2); font-size: 13.5px; display: block; padding: 3px 8px; border-radius: 6px; }
.toc-list a:hover { color: var(--primary); background: var(--primary-soft); }
.toc-list a.toc-h2 { font-weight: 600; }
.toc-list a.toc-h3 { padding-left: 22px; font-size: 13px; }
.toc-list a.toc-h4 { padding-left: 36px; font-size: 12.5px; }
.toc-list::-webkit-scrollbar { width: 4px; }
.toc-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---------- 归档 / 分类 / 标签 页面 ---------- */
.page-title { font-size: 26px; font-weight: 700; margin-bottom: 22px; display: flex; align-items: center; gap: 10px; }
.page-title i { font-style: normal; color: var(--primary); }
.archive-year { font-size: 19px; font-weight: 700; margin: 26px 0 12px; color: var(--primary); }
.archive-item {
  display: flex; align-items: baseline; gap: 14px; padding: 10px 0;
  border-bottom: 1px dashed var(--border); font-size: 15px;
}
.archive-item time { color: var(--text-2); font-size: 13px; flex: 0 0 80px; }
.archive-item a { color: var(--text); }
.archive-item a:hover { color: var(--primary); }
.archive-item .cat-pill { margin-left: auto; font-size: 12px; color: var(--text-2); background: var(--bg); padding: 1px 10px; border-radius: 20px; }

.cat-section { margin-bottom: 30px; }
.cat-section-head { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.cat-section-head .count { color: var(--primary); background: var(--primary-soft); padding: 0 10px; border-radius: 20px; font-size: 13px; }

.tag-cloud-page { display: flex; flex-wrap: wrap; gap: 12px; }
.tag-page-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 22px;
  padding: 6px 16px; color: var(--text); font-size: 14px; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 6px;
}
.tag-page-item:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.tag-page-item span { font-size: 12px; opacity: 0.8; }

/* ---------- 关于页 ---------- */
.about-card { margin-bottom: 22px; }
.about-section { margin: 1.4em 0; }
.about-section h2 { font-size: 20px; margin-bottom: 0.6em; padding-left: 12px; border-left: 4px solid var(--primary); }
.about-section p, .about-section li { color: var(--text-2); }
.about-section ul { padding-left: 1.5em; }
.route-step { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.route-step .idx {
  flex: 0 0 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.route-step h4 { font-size: 15.5px; }
.route-step p { font-size: 13.5px; color: var(--text-2); }

/* ---------- 页脚 ---------- */
#footer {
  border-top: 1px solid var(--border); background: var(--card);
  padding: 26px 20px; text-align: center; color: var(--text-2); font-size: 13px;
}
#footer a { color: var(--text-2); }
#footer a:hover { color: var(--primary); }
#footer .sep { margin: 0 8px; opacity: 0.5; }

/* ---------- 悬浮按钮 ---------- */
#rightside {
  position: fixed; right: 22px; bottom: 30px; z-index: 800;
  display: flex; flex-direction: column; gap: 10px;
}
.rt-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); cursor: pointer; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: all 0.25s;
}
.rt-btn.show { opacity: 1; transform: none; pointer-events: auto; }
.rt-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.rt-btn .percent { font-size: 11px; font-weight: 700; position: absolute; }

/* ---------- 搜索 ---------- */
#search-mask {
  position: fixed; inset: 0; background: rgba(10, 20, 40, 0.5); backdrop-filter: blur(3px);
  z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
#search-mask.show { opacity: 1; pointer-events: auto; }
#search-modal {
  position: fixed; top: 12vh; left: 50%; transform: translateX(-50%) translateY(-12px);
  width: min(680px, 92vw); background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.4); z-index: 1001;
  opacity: 0; pointer-events: none; transition: all 0.25s; overflow: hidden;
}
#search-modal.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.search-head { display: flex; align-items: center; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.search-head input {
  flex: 1; border: none; outline: none; background: transparent; color: var(--text);
  font-size: 16px; font-family: var(--font);
}
.search-head .close-btn { background: none; border: none; cursor: pointer; color: var(--text-2); font-size: 15px; }
.search-results { max-height: 58vh; overflow-y: auto; padding: 8px 12px; }
.search-result-item { display: block; padding: 12px 10px; border-radius: 10px; }
.search-result-item:hover { background: var(--primary-soft); }
.search-result-item h4 { font-size: 15px; color: var(--text); margin-bottom: 4px; }
.search-result-item p { font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-empty { padding: 40px 20px; text-align: center; color: var(--text-2); }

/* ---------- 404 ---------- */
.nf404 { text-align: center; padding: 90px 20px; }
.nf404 h1 { font-size: 80px; background: linear-gradient(135deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nf404 p { color: var(--text-2); margin: 12px 0 24px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .aside-content { position: static; order: 2; }
}
@media (max-width: 860px) {
  #menus .menu-link { display: none; }
  #toggle-menu { display: inline-flex; }
  #nav { padding: 0 16px; }
  #menus.open { position: absolute; top: calc(var(--nav-h) + 6px); right: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-hover); padding: 8px; flex-direction: column; align-items: stretch; min-width: 150px; }
  #menus.open .menu-link { display: flex; align-items: center; gap: 8px; }
  .recent-post-item { flex-direction: column; }
  .post-cover { flex-basis: auto; height: 200px; }
  .post-content, .post-header { padding: 24px 20px; }
  .hero--full { min-height: 66vh; }
}
@media (max-width: 560px) {
  .post-cover { height: 170px; }
  .article-title { font-size: 18px; }
  .archive-item .cat-pill { display: none; }
}
