/* ========================================
   felixd.dev 样式表
   
   结构：
   1. CSS 变量 & Reset
   2. 基础排版
   3. 站点布局
   4. 文章内容 (.md)
   5. 组件样式
   6. 响应式
   ======================================== */

/* ========================================
   1. Reset & 基础
   ======================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color: var(--page-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue",
    Helvetica, Arial, sans-serif;
  font-size: 20px;
  font-weight: 450;
  line-height: 1.75;
  background-color: var(--page-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ========================================
   2. 基础排版 - 全局元素默认样式
   ======================================== */

/* 标题 */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  color: var(--heading-text);
  font-weight: 600;
  line-height: 1.3;
}

h1 {
  font-size: 1.875em;
}

h2 {
  font-size: 1.5em;
}

h3 {
  font-size: 1.25em;
}

h4 {
  font-size: 1.125em;
}

h5,
h6 {
  font-size: 1em;
}

/* 段落 & 文本 */
p {
  margin: 0;
}

strong,
b {
  color: var(--strong-text);
  font-weight: 600;
}

/* 链接 */
a {
  color: var(--link-text);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

/* 列表 */
ul,
ol {
  margin: 0;
  padding-left: 1.5em;
}

li {
  line-height: 1.65;
}

/* 代码 */
code {
  font-family: "SF Mono", "Fira Code", Menlo, Monaco, Consolas, monospace;
  font-size: 0.875em;
  background-color: var(--inline-code-bg);
  padding: 0.125em 0.375em;
  border-radius: 4px;
}

pre {
  margin: 0;
  padding: 1em;
  overflow-x: auto;
  font-size: 0.875em;
  line-height: 1.5;
  background-color: var(--code-bg);
  border: 1px solid var(--code-border-color);
  border-radius: 8px;
}

pre code {
  padding: 0;
  background: transparent;
  font-size: inherit;
}

/* 引用 */
blockquote {
  margin: 0;
  padding: 0.75em 1em;
  border-left: 3px solid var(--blockquote-border);
  background-color: var(--blockquote-bg);
  border-radius: 0 6px 6px 0;
}

/* 表格 */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}

th,
td {
  padding: 0.625em 1em;
  border: 1px solid var(--border-color);
  text-align: left;
}

th {
  font-weight: 600;
  background-color: var(--table-header-bg);
}

/* 分隔线 */
hr {
  border: none;
  border-top: 1px solid var(--hr-color);
  margin: 2em 0;
}

/* 图片 */
img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

/* ========================================
   3. 站点布局
   ======================================== */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 1em;
  margin-bottom: 2em;
  border-bottom: 1px solid var(--border-color);
}

.site-header nav {
  display: flex;
  gap: 0.5em;
  font-size: 0.95em;
}

.site-title {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0;
}

footer {
  margin-top: auto;
  padding-top: 2em;
  /* border-top: 1px solid var(--border-color); */
  text-align: center;
  font-size: 0.875em;
  opacity: 0.6;
}

footer hr {
  display: none;
}

/* ========================================
   4. 文章内容 (.md)
   统一的垂直节奏：段落间 1em，章节间 1.5em
   ======================================== */

.md {
  line-height: 1.75;
  --md-flow-space: 0.95em;
  --md-flow-space-tight: 0.5em;
  --md-heading-space: 1.75em;
  --md-hr-space: 2em;
}

/* 块级元素的垂直节奏 */
.md>*+* {
  margin-top: var(--md-flow-space);
}

/* 标题前需要更大间距（章节分隔感） */
.md>*+h1,
.md>*+h2,
.md>*+h3,
.md>*+h4 {
  margin-top: var(--md-heading-space);
}

/* 标题后紧跟内容，间距收紧 */
.md>h1+*,
.md>h2+*,
.md>h3+*,
.md>h4+* {
  margin-top: var(--md-flow-space-tight);
}

/* 段落后紧跟列表时，间距略收紧 */
.md>p+ul,
.md>p+ol {
  margin-top: 0.6em;
}

/* 列表后紧跟段落时，间距略放开一点点 */
.md>ul+p,
.md>ol+p {
  margin-top: 0.85em;
}

/* 列表项间距 */
.md li+li {
  margin-top: 0.25em;
}

.md li>ul,
.md li>ol {
  margin-top: 0.375em;
}

/* 引用块内段落 */
.md blockquote>*+* {
  margin-top: 0.5em;
}

/* 图片居中 + 上下留白 */
.md img {
  margin: 1.5em auto;
}

/* 分隔线在 .md 内保持上下对称，不被通用 flow 规则干扰 */
.md>hr {
  margin: var(--md-hr-space) 0;
}

/* ========================================
   5. 组件样式
   ======================================== */

/* 页面/文章标题区（独立于 markdown 内容） */
.page-header {
  margin: 0 0 1.2em;
}

.post-header {
  margin: 0 0 1em;
}

.page-title,
.post-title {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.post-meta {
  margin-top: 0.35em;
  font-size: 0.9em;
  color: var(--muted-text);
}

.post-meta a {
  color: inherit;
  text-decoration: none;
}

.post-meta a:hover {
  text-decoration: underline;
  text-decoration-thickness: 0.1em;
  text-underline-offset: 0.18em;
}

/* 博客列表（日期 + 标题） */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 0.9em;
}

.post-list-item {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.post-list-date {
  flex: 0 0 auto;
  font-size: 0.875em;
  color: var(--muted-text);
  white-space: nowrap;
}

.post-list-title {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
}

.date {
  font-size: 0.8em;
  color: #2a7ae2;
  text-decoration: none;
}

.post-list-title:hover {
  text-decoration: underline;
}

.post-list-title h3 {
  color: #2a7ae2;
  font-size: 1.1em;
}

/* 任务列表 */
ul.contains-task-list {
  list-style: none;
  padding-left: 0;
}

.task-list-item {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.task-list-item input[type="checkbox"] {
  margin: 0;
}

/* 区块组件 */
.block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.5em 1em;
  border: 1px dotted var(--border-color);
  border-radius: 6px;
  text-align: center;
}

.block h1 {
  font-size: 1em;
  margin: 0;
}

.small {
  font-size: 0.875em;
  opacity: 0.7;
}

.wave {
  background: var(--wave-bg, #111);
  color: var(--wave-text, #fff);
  text-shadow: var(--wave-shadow, 1px 1px 10px #fff, 1px 1px 10px #ccc);
}

/* 首页：介绍（独占）+ 探索/Lab（两列）+ 尾部（独占）
   说明：index.smd 禁止 HTML，所以在 layouts/index.shtml 用 JS 把内容拆成：
   .index-intro / .index-columns(.index-col*2) / .index-tail
*/

/* 保持 markdown 的垂直节奏（因为内容被包进了 wrapper，不再是 .md 的直接子元素） */
.index-content :where(.index-intro, .index-col, .index-tail) > * + * {
  margin-top: var(--md-flow-space);
}

.index-content :where(.index-intro, .index-col, .index-tail) > * + h1,
.index-content :where(.index-intro, .index-col, .index-tail) > * + h2,
.index-content :where(.index-intro, .index-col, .index-tail) > * + h3,
.index-content :where(.index-intro, .index-col, .index-tail) > * + h4 {
  margin-top: var(--md-heading-space);
}

.index-content :where(.index-intro, .index-col, .index-tail) > h1 + *,
.index-content :where(.index-intro, .index-col, .index-tail) > h2 + *,
.index-content :where(.index-intro, .index-col, .index-tail) > h3 + *,
.index-content :where(.index-intro, .index-col, .index-tail) > h4 + * {
  margin-top: var(--md-flow-space-tight);
}

.index-content :where(.index-intro, .index-col, .index-tail) > p + ul,
.index-content :where(.index-intro, .index-col, .index-tail) > p + ol {
  margin-top: 0.6em;
}

.index-content :where(.index-intro, .index-col, .index-tail) > ul + p,
.index-content :where(.index-intro, .index-col, .index-tail) > ol + p {
  margin-top: 0.85em;
}

.index-content :where(.index-intro, .index-col, .index-tail) > hr {
  margin: var(--md-hr-space) 0;
}

/* 两列并排 */
.index-content .index-columns {
  display: flex;
  gap: 3em;
  align-items: flex-start;
}

.index-content .index-col {
  flex: 1 1 0;
  min-width: 0; /* 防止长链接/代码导致溢出 */
}

/* 尾部独占（例如：全部文章 →） */
.index-content .index-tail {
  text-align: center;
  margin-top: 2em;
}

.index-content .index-tail a {
  font-weight: 600;
}

/* ========================================
   6. 响应式
   ======================================== */

@media (max-width: 800px) {
  .index-content .index-columns {
    flex-direction: column;
    gap: 2em;
  }
}

@media (max-width: 640px) {
  html {
    font-size: 17px;
  }

  body {
    padding: 16px 20px;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  pre {
    padding: 0.75em;
    border-radius: 6px;
  }
}

/* ========================================
   7. 代码语法高亮 (VS Code Theme)
   语言无关的统一配色，颜色变量定义在 theme.css
   ======================================== */

/* 代码块基础文本色 */
pre code {
  color: var(--hl-base);
}

/* ---- 语言无关的语法高亮规则 ---- */

/* 注释 */
code .comment {
  color: var(--hl-comment);
  font-style: italic;
}

/* 关键字 */
code .keyword {
  color: var(--hl-keyword);
}

/* 控制流关键字 (if/else/return/match/for/while) */
code .keyword.control,
code .keyword.conditional,
code .keyword.return {
  color: var(--hl-control);
}

/* 字符串 */
code .string {
  color: var(--hl-string);
}

/* 函数名、方法名 */
code .function,
code .method {
  color: var(--hl-function);
}

/* 变量、参数 */
code .variable,
code .parameter {
  color: var(--hl-variable);
}

/* 类型、结构体、枚举、接口 */
code .type,
code .class,
code .struct,
code .enum,
code .interface {
  color: var(--hl-type);
}

/* 数字、常量 */
code .number,
code .constant {
  color: var(--hl-number);
}

/* 运算符 */
code .operator {
  color: var(--hl-operator);
}

/* 属性、字段 */
code .property,
code .field {
  color: var(--hl-property);
}

/* 宏 */
code .macro {
  color: var(--hl-macro);
}

/* 属性标注 (#[derive], @decorator) */
code .attribute {
  color: var(--hl-attribute);
}

/* 内置函数 */
code .builtin {
  color: var(--hl-builtin);
}

/* 标点符号 - 保持低调 */
code .punctuation,
code .bracket {
  color: var(--hl-base);
}

/* ASCII 流程图 - 保持等宽，不加颜色 */
code.ascii,
code.text,
pre.ascii,
pre.text {
  color: var(--page-text);
  font-family: "SF Mono", "Fira Code", Menlo, Monaco, Consolas, monospace;
  line-height: 1.4;
}