/* ===== 设计 Token：绿色自然系 ===== */
:root {
  --ink: #122319;          /* 深墨绿 - 主色、文字、深色按钮 */
  --text: #243d2e;         /* 正文段落色 - 比墨绿稍浅，便于阅读 */
  --muted: #6e7c73;        /* 灰绿 - 次级文字 */
  --line: #dfe5df;         /* 浅绿灰 - 边框、分割线 */
  --paper: #f4f6f1;        /* 纸白 - 页面背景（带微绿） */
  --card: #fbfcf8;         /* 卡片白 - 卡片背景 */
  --green: #42e179;        /* 鲜绿 - 成功、激活态 */
  --green-dark: #103d23;   /* 森林深绿 - hover、强调 */
  --green-soft: rgba(66, 225, 121, 0.12); /* 浅绿底 */
  --orange: #ff6934;       /* 暖橙 - 警示、次要强调 */
  --shadow: 0 24px 70px rgba(27, 49, 35, 0.09);
  --shadow-sm: 0 8px 24px rgba(18, 35, 25, 0.08);
  --radius: 9px;
  --radius-lg: 12px;
  --sidebar-width: 250px;
}

/* 暗色主题（给 <html> 或 <body> 加 .dark 即生效） */
:root.dark {
  color-scheme: dark;
  --ink: #e7f0e9;          /* 亮色文字 */
  --text: #c7d3cb;         /* 正文 */
  --muted: #8ea094;        /* 次级文字 */
  --line: #2a3c32;         /* 深色分割线 */
  --paper: #0d1b14;        /* 页面背景 */
  --card: #13281d;         /* 卡片背景 */
  --green: #42e179;        /* 鲜绿 - 保持高饱和以突出 */
  --green-dark: #86f0ab;   /* 森林浅绿 - 暗色模式下作为可读强调 */
  --green-soft: rgba(66, 225, 121, 0.14);
  --orange: #ff8254;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: "DM Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  position: relative;
  left: 0;
  transition: left 0.3s ease, background 0.3s ease, color 0.3s ease;
}
/* 让主题切换时受 CSS 变量影响的元素也有过渡 */
.container, .sidebar, footer, .article-item, .hobby-item, .sidebar-toggle,
.content-section h2, header, .article-content pre {
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* 页面微纹理背景（SVG noise） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.022;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ===== 主内容容器（卡片化） ===== */
.container {
  position: relative;
  z-index: 1;
  max-width: 1000px;
  margin: 40px auto;
  padding: 40px;
  background: var(--card);
  border: 1px solid rgba(18, 35, 25, 0.07);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: left 0.3s ease;
}

/* ===== 侧边栏开关按钮 ===== */
.sidebar-toggle {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 999;
  background: var(--green);
  color: var(--green-dark);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(66, 225, 121, 0.4);
  transition: all 0.2s ease;
  padding: 0;
}
.sidebar-toggle:hover {
  background: #34c769;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(66, 225, 121, 0.5);
}

/* ===== 明暗主题切换按钮（右上角） ===== */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 999;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s ease;
  padding: 0;
  overflow: hidden;
}
.theme-toggle:hover {
  transform: translateY(-2px);
  border-color: var(--green);
  box-shadow: 0 6px 20px rgba(66, 225, 121, 0.25);
}
.theme-toggle i { transition: transform 0.3s ease, opacity 0.2s ease; position: absolute; }
.theme-toggle .icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.6); color: #f5b13e; }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0) scale(1); color: var(--ink); }
:root.dark .theme-toggle .icon-sun { opacity: 1; transform: rotate(0) scale(1); }
:root.dark .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.6); }

/* ===== 侧边栏（深墨绿） ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: calc(-1 * var(--sidebar-width));
  width: var(--sidebar-width);
  height: 100%;
  background: linear-gradient(180deg, #122319 0%, #1a3a28 100%);
  color: #e7f0e9;
  padding: 20px;
  box-sizing: border-box;
  transition: left 0.3s ease;
  z-index: 998;
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(18, 35, 25, 0.25);
}
.sidebar-open .sidebar { left: 0; }
.sidebar-open .container { left: var(--sidebar-width); }

.sidebar-header {
  padding: 20px 0;
  text-align: center;
  border-bottom: 1px solid rgba(66, 225, 121, 0.2);
  margin-bottom: 20px;
}
.sidebar-title {
  background: linear-gradient(135deg, var(--green), #6ef0a8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.sidebar-menu { list-style: none; padding: 0; margin: 0; }
.sidebar-menu li { margin-bottom: 5px; }

.sidebar-menu a {
  display: block;
  color: #cdd9d0;
  padding: 10px 15px;
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.sidebar-menu a:hover {
  background: rgba(66, 225, 121, 0.1);
  color: var(--green);
  border-color: rgba(66, 225, 121, 0.2);
  padding-left: 20px;
}
.sidebar-menu a.active {
  background: var(--green);
  color: var(--green-dark);
  font-weight: 600;
}
.sidebar-menu a i {
  margin-right: 10px;
  width: 20px;
  text-align: center;
  color: var(--green);
}
.sidebar-menu a.active i { color: var(--green-dark); }

/* 二级菜单 */
.submenu { list-style: none; padding-left: 20px; margin-top: 5px; display: none; }
.submenu.active { display: block; }
.submenu a { padding: 8px 15px 8px 30px; font-size: 0.9rem; background: rgba(0, 0, 0, 0.18); }

.has-submenu > a:after {
  content: '\f107';
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  float: right;
  transition: transform 0.3s;
}
.has-submenu.active > a:after { transform: rotate(180deg); }

/* ===== 标题区 ===== */
header {
  text-align: center;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 30px;
  position: relative;
}
header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--green), transparent);
}

h1 {
  color: var(--ink);
  margin-bottom: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: clamp(28px, 4vw, 44px);
  word-break: break-word;
}
.subtitle {
  color: var(--muted);
  font-weight: normal;
  letter-spacing: 1px;
  font-size: 13px;
}

.content-section { margin-bottom: 40px; }

h2 {
  color: var(--ink);
  border-bottom: 2px solid var(--line);
  padding-bottom: 10px;
  margin-top: 40px;
  font-weight: 600;
  font-size: 20px;
  position: relative;
}
h2::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 1.2em;
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  margin-right: 10px;
  vertical-align: middle;
  border-radius: 2px;
}

/* ===== 关于我 ===== */
.about-me { display: flex; align-items: center; gap: 30px; }
.about-text { flex: 1; }
.about-text p { color: var(--text); margin-bottom: 12px; }
.about-text p:last-child { margin-bottom: 0; }

/* ===== 兴趣标签 ===== */
.hobby-list { display: flex; flex-wrap: wrap; gap: 12px; }
.hobby-item {
  background: var(--green-soft);
  color: var(--green-dark);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  border: 1px solid rgba(66, 225, 121, 0.3);
  transition: all 0.3s ease;
}
.hobby-item:hover {
  border-color: var(--green);
  box-shadow: 0 4px 12px rgba(66, 225, 121, 0.25);
  transform: translateY(-2px);
}

/* ===== 联系方式 ===== */
.contact-list { list-style: none; padding: 0; }
.contact-list li {
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  color: var(--text);
}
.contact-list i {
  margin-right: 10px;
  color: var(--green-dark);
  font-size: 18px;
  width: 20px;
  text-align: center;
}
.contact-list a {
  color: var(--green-dark);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.2s;
}
.contact-list a:hover { border-bottom-color: var(--green-dark); }

/* 复制按钮 */
.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--green-dark);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 13px;
  margin-left: 6px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.copy-btn:hover {
  background: var(--green);
  color: var(--ink);
  border-color: var(--green);
  transform: translateY(-1px);
}
.copy-btn.copied {
  background: var(--green-dark);
  color: #fff;
  border-color: var(--green-dark);
}

/* 飘字堆叠容器：固定在视口底部居中，新飘字追加在底部，把已有飘字往上顶 */
#toast-stack {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 10000;
  pointer-events: none;
}
/* 单条飘字的占位包裹层：通过 max-height 与间距过渡，实现平滑的展开/收拢 */
.copy-toast-item {
  max-height: 0;
  margin-bottom: 0;
  transition: max-height 0.25s ease, margin-bottom 0.25s ease;
}
/* 复制成功飘字提示 */
.copy-toast {
  padding: 12px 24px;
  background: var(--green-dark);
  color: #fff;
  font-size: 14px;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}
.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}
/* 暗色模式下 toast：深墨绿底 + 淡绿白字，保证高对比 */
:root.dark .copy-toast {
  background: #05140c;
  color: #e7f0e9;
  border: 1px solid rgba(66, 225, 121, 0.25);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}

/* 首页学习笔记列表 */
.content-section ul li a {
  color: var(--green-dark);
  text-decoration: none;
  transition: color 0.2s;
}
.content-section ul li a:hover { color: var(--green); }
.content-section ul { color: var(--text); }
.content-section ul li { margin-bottom: 8px; }

/* ===== 文章列表页 ===== */
.article-category-title {
  color: var(--ink);
  border-bottom: 2px solid var(--green);
  padding-bottom: 10px;
  margin-top: 20px;
  font-weight: 700;
  font-size: 22px;
}
.article-list { list-style: none; padding: 0; }
.article-item {
  padding: 18px 20px;
  margin-bottom: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: all 0.3s ease;
}
.article-item:hover {
  background: var(--card);
  border-color: var(--green);
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}
.article-title {
  font-size: 1.1rem;
  color: var(--green-dark);
  margin-bottom: 5px;
  display: block;
  text-decoration: none;
  font-weight: 600;
}
.article-title:hover { color: var(--green); }
.article-date { font-size: 0.85rem; color: var(--muted); }

/* ===== 返回按钮（链接式） ===== */
.back-to-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 20px;
  padding: 10px 18px;
  /* 使用主题相关变量：暗色下 --ink 为浅色，因此改为"永远深色底"的语义变量，显式覆盖 */
  background: var(--btn-bg, var(--ink));
  color: var(--btn-text, #fff);
  text-decoration: none;
  border: none;
  border-radius: var(--radius);
  transition: all 0.2s ease;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.back-to-home:hover {
  background: var(--btn-hover, var(--green-dark));
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.back-to-home i { color: var(--green); }

/* ===== 文章详情页 ===== */
.article-header {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.article-header .article-title {
  font-size: 1.8rem;
  color: var(--ink);
  margin-bottom: 10px;
  font-weight: 700;
  line-height: 1.3;
}
.article-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}
.article-content { line-height: 1.8; color: var(--text); }
.article-content h2,
.article-content h3 { color: var(--green-dark); margin-top: 28px; }
.article-content p { margin-bottom: 20px; color: var(--text); }
.article-content a { color: var(--green-dark); }
.article-content ul,
.article-content ol { color: var(--text); }
.article-content pre {
  background: #101b14;
  color: #b8f5cf;
  padding: 18px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 20px;
  border: 1px solid rgba(66, 225, 121, 0.15);
  font-size: 13px;
  line-height: 1.55;
}
.article-content code {
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  background: var(--green-soft);
  color: var(--green-dark);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.95em;
}
.article-content pre code {
  background: transparent;
  color: #b8f5cf;
  padding: 0;
}

/* ===== 页脚（全站唯一） ===== */
footer {
  text-align: center;
  padding-top: 30px;
  border-top: 1px solid var(--line);
  margin-top: 50px;
  font-size: 14px;
  color: var(--muted);
}
.icp {
  margin-top: 20px;
  padding: 10px 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-block;
}
.icp a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}
.icp a:hover { color: var(--green-dark); }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--paper); }
::-webkit-scrollbar-thumb { background: rgba(66, 225, 121, 0.4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--green); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .about-me { flex-direction: column; }
  .container { padding: 20px; margin: 20px; }
  .sidebar-open .container {
    left: 0;
    transform: translateX(var(--sidebar-width));
  }
  h1 { font-size: 26px; }
}

/* ===== 暗色模式：针对硬编码颜色的补偿 ===== */
:root.dark .article-content pre {
  background: #050c08;
  border-color: rgba(66, 225, 121, 0.2);
  color: #9fe8bb;
}
:root.dark ::-webkit-scrollbar-track { background: transparent; }
:root.dark ::-webkit-scrollbar-thumb { background: rgba(66, 225, 121, 0.3); }
:root.dark ::-webkit-scrollbar-thumb:hover { background: rgba(66, 225, 121, 0.55); }
:root.dark body::before { opacity: 0.018; }

/* 暗色模式下按钮：保持深底+白字高对比，不跟随 --ink 变浅 */
:root.dark .back-to-home {
  --btn-bg: #0a1811;
  --btn-text: #e7f0e9;
  --btn-hover: #103d23;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
