
/* ==============================
   STM32 Learning Design System
   Inspired by u.sb Design System
   ============================== */

:root {
  color-scheme: light;

  --background: #f5f5f5;
  --foreground: #0c0a09;
  --card: #ffffff;
  --secondary: #f0efed;
  --content: #3f3d3a;
  --muted: #777169;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --primary: #292524;
  --link-wave: #777169;
  --sparkle: #a8a29e;
  --code-bg: #fbf1c7;
  --code-text: #504945;

  --shadow-sm: 0 2px 8px rgb(12 10 9 / 4%);
  --shadow-md: 0 4px 16px rgb(12 10 9 / 6%);

  --font-sans: "Space Grotesk",
    "PingFang SC", "Microsoft YaHei",
    "Noto Sans CJK SC", sans-serif;

  --font-mono: "SFMono-Regular", Consolas,
    "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --background: #0c0a09;
  --foreground: #f5f5f4;
  --card: #231d18;
  --secondary: #292524;
  --content: #d6d3d1;
  --muted: #a8a29e;
  --border: #2a2624;
  --border-strong: #44403c;
  --primary: #f5f5f4;
  --link-wave: #ffcc00;
  --sparkle: #ffcc00;
  --code-bg: #171412;
  --code-text: #d5c4a1;
}

/* 页面基础 */

html {
  background: var(--background);
  scroll-behavior: smooth;
}

body {
  background: var(--background);
  color: var(--content);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.85;
  min-height: 100vh;
}

/* 替换 Cayman 顶部横幅 */

.page-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px !important;
  background: transparent !important;
  background-image: none !important;
  color: var(--foreground);
  border-bottom: 1px solid var(--border);

  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  text-align: left;
}

.project-name {
  margin: 0;
  font-size: 17px !important;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.project-tagline,
.page-header > .btn {
  display: none;
}

/* 顶部导航 */

.site-actions {
  display: flex;
  align-items: center;
  gap: 22px;
}

.nav-link {
  font-size: 13px;
  font-weight: 600;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--card);
  color: var(--foreground);
  cursor: pointer;
  font-size: 19px;
  transition: background .2s, transform .2s;
}

.theme-toggle:hover {
  background: var(--secondary);
  transform: rotate(12deg);
}

.theme-toggle:focus-visible,
a:focus-visible,
.copy-btn:focus-visible {
  outline: 2px solid var(--link-wave);
  outline-offset: 3px;
}

/* 主要内容 */

.main-content {
  position: relative;
  max-width: 960px;
  padding: 48px 24px 80px;
  color: var(--content);
  font-family: var(--font-sans);
}

.main-content h1,
.main-content h2,
.main-content h3,
.main-content h4 {
  color: var(--foreground);
  font-weight: 700;
  letter-spacing: -0.035em;
}

.main-content h1 {
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.25;
  margin-bottom: 24px;
}

.main-content h2 {
  margin-top: 44px;
  padding-bottom: 12px;
  font-size: 23px;
  border-bottom: 1px solid var(--border);
}

.main-content h3 {
  font-size: 19px;
}

.main-content p,
.main-content li {
  color: var(--content);
}

.main-content hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 36px 0;
}

/* 波浪下划线 */

.main-content a,
.nav-link {
  color: var(--foreground);
  text-decoration: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='5' viewBox='0 0 20 5'%3E%3Cpath d='M0 3 Q2.5 0 5 3 T10 3 T15 3 T20 3' stroke='%23a8a29e' stroke-width='1.2' fill='none'/%3E%3C/svg%3E");
  background-position: left bottom;
  background-repeat: repeat-x;
  background-size: 0 5px;
  transition: color .25s, background-size .3s;
}

.main-content a:hover,
.nav-link:hover,
.nav-link.active {
  color: var(--link-wave);
  background-size: 20px 5px;
}

:root[data-theme="dark"] .main-content a:hover,
:root[data-theme="dark"] .nav-link:hover,
:root[data-theme="dark"] .nav-link.active {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: #ffcc00;
  text-underline-offset: 5px;
}

/* 首页文章卡片 */

.home-page .main-content > ul {
  list-style: none;
  padding: 0;
  margin: 20px 0 32px;
}

.home-page .main-content > ul > li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  margin: 12px 0;
  padding: 17px 20px;
  transition:
    transform .25s,
    box-shadow .25s,
    border-color .25s;
}

.home-page .main-content > ul > li:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.home-page .main-content > ul > li a {
  display: block;
  font-weight: 600;
}

/* 行内代码 */

.main-content :not(pre) > code {
  font-family: var(--font-mono);
  font-size: .88em;
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--secondary);
  color: var(--foreground);
}

:root[data-theme="dark"]
.main-content :not(pre) > code {
  background: #3b2e19;
  color: #f0d9a5;
  border: 1px solid #55411f;
}

/* 代码窗口 */

.code-window {
  overflow: hidden;
  border-radius: 12px;
  margin: 22px 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 15px;
  border-bottom: 1px solid var(--border);
}

.code-dots {
  display: flex;
  gap: 7px;
}

.code-dots i {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.code-dots i:nth-child(1) {
  background: #ff5f57;
}

.code-dots i:nth-child(2) {
  background: #febc2e;
}

.code-dots i:nth-child(3) {
  background: #28c840;
}

.code-language {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  margin-left: auto;
  margin-right: 16px;
}

.copy-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--foreground);
}

.main-content .code-window pre {
  background: transparent !important;
  border: 0 !important;
  margin: 0 !important;
  padding: 20px !important;
  overflow-x: auto;
}

.main-content .code-window pre code {
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

.highlight,
.highlighter-rouge {
  background: transparent !important;
}

/* 基础 Gruvbox 语法颜色 */

:root {
  --syntax-keyword: #9d0006;
  --syntax-string: #79740e;
  --syntax-comment: #928374;
  --syntax-number: #8f3f71;
}

:root[data-theme="dark"] {
  --syntax-keyword: #fb4934;
  --syntax-string: #b8bb26;
  --syntax-comment: #928374;
  --syntax-number: #d3869b;
}

.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .nt {
  color: var(--syntax-keyword);
}

.highlight .s,
.highlight .s1,
.highlight .s2 {
  color: var(--syntax-string);
}

.highlight .c,
.highlight .c1,
.highlight .cm {
  color: var(--syntax-comment);
}

.highlight .m,
.highlight .mi,
.highlight .mf {
  color: var(--syntax-number);
}

/* 表格、引用与图片 */

.main-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.main-content table th,
.main-content table td {
  background: var(--card);
  color: var(--content);
  border-color: var(--border);
}

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

.main-content blockquote {
  border-left: 3px solid var(--link-wave);
  background: var(--secondary);
  border-radius: 0 8px 8px 0;
  padding: 12px 18px;
  color: var(--content);
}

.main-content img {
  max-width: 100%;
  border-radius: 12px;
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
}

/* 首页星空 */

.hero-stars {
  position: absolute;
  top: 35px;
  right: 45px;
  width: 210px;
  height: 130px;
  pointer-events: none;
}

.hero-stars span {
  position: absolute;
  color: var(--sparkle);
  font-size: 17px;
  animation: twinkle 3s ease-in-out infinite;
}

.hero-stars span:nth-child(1) {
  top: 10%;
  left: 20%;
}

.hero-stars span:nth-child(2) {
  top: 35%;
  left: 75%;
  animation-delay: .8s;
}

.hero-stars span:nth-child(3) {
  top: 70%;
  left: 43%;
  animation-delay: 1.6s;
}

.hero-stars span:nth-child(4) {
  top: 5%;
  left: 90%;
  font-size: 9px;
  animation-delay: 2s;
}

@keyframes twinkle {
  0%, 100% {
    opacity: .3;
    transform: scale(.8);
  }

  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

.cursor-spark {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  color: var(--sparkle);
  animation: spark-fade .7s ease-out forwards;
}

@keyframes spark-fade {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-18px) scale(.4);
  }
}

/* 小屏适配 */

@media (max-width: 650px) {
  .page-header {
    padding: 18px 20px !important;
  }

  .main-content {
    padding: 32px 20px 60px;
  }

  .hero-stars {
    width: 85px;
    right: 12px;
    top: 16px;
    opacity: .6;
  }

  .main-content h1 {
    padding-right: 30px;
  }

  .site-actions {
    gap: 12px;
  }
}

/* 尊重减少动画偏好 */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .cursor-spark {
    display: none;
  }
}

/* Article layout: warm paper, compact masthead and readable measure. */
* { box-sizing: border-box; }
body { margin: 0; }
.page-header { max-width: 1080px; padding: 22px 32px !important; }
.page-header .project-name { line-height: 1.4; }
.main-content {
  max-width: 880px;
  margin: 40px auto 72px;
  padding: 48px 56px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  font-size: 16px;
  line-height: 1.85;
  overflow-wrap: anywhere;
}
.main-content > :first-child { margin-top: 0; }
.main-content h1 { font-size: clamp(26px, 3.4vw, 36px); line-height: 1.4; letter-spacing: -.025em; margin: 0 0 32px; }
.main-content h2 { font-size: 24px; line-height: 1.5; padding-bottom: 0; border-bottom: 0; margin: 44px 0 18px; }
.main-content h3 { font-size: 19px; line-height: 1.6; margin: 28px 0 12px; }
.main-content h2, .main-content h3, .main-content h4 { scroll-margin-top: 24px; }
.main-content p { margin: 0 0 20px; }
.main-content ul, .main-content ol { padding-left: 1.6em; margin-bottom: 24px; }
.main-content li + li { margin-top: 6px; }
.main-content strong { color: var(--foreground); font-weight: 600; }
.main-content hr { margin: 36px 0; }
.main-content a { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 4px; }
.main-content a:hover, .nav-link:hover, .nav-link.active {
  background-image: none;
  text-decoration: underline wavy var(--link-wave);
  text-underline-offset: 5px;
}
.code-toolbar { gap: 12px; padding: 10px 16px; }
.code-dots { flex-shrink: 0; }
.code-language { margin-left: 4px; margin-right: auto; }
.copy-btn { min-height: 28px; padding: 3px 8px; border-radius: 6px; }
.copy-btn:hover { background: var(--secondary); }
.main-content .code-window pre { padding: 18px 20px !important; line-height: 1.7; }
.main-content .code-window pre code { font-size: 13px; white-space: pre; overflow-wrap: normal; }
.main-content .code-window pre code span { background: transparent; }
/* Override all Cayman/Rouge groups, including names, builtins and operators. */
.highlight .highlight { background: transparent; }
.highlight .n, .highlight .na, .highlight .nb, .highlight .nc,
.highlight .nd, .highlight .ne, .highlight .nf, .highlight .nl,
.highlight .nn, .highlight .nx, .highlight .bp, .highlight .o,
.highlight .ow, .highlight .p, .highlight .w { color: var(--code-text); }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn,
.highlight .kp, .highlight .kr, .highlight .kt, .highlight .nt { color: var(--syntax-keyword); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sa,
.highlight .sb, .highlight .sc, .highlight .sd, .highlight .se,
.highlight .sh, .highlight .si, .highlight .sr, .highlight .ss { color: var(--syntax-string); }
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cp,
.highlight .cs, .highlight .ch { color: var(--syntax-comment); font-style: italic; }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh,
.highlight .mo, .highlight .mb, .highlight .il { color: var(--syntax-number); }
.main-content table { border-spacing: 0; margin: 22px 0; font-size: 14px; }
.main-content table th { background: var(--secondary); color: var(--foreground); font-weight: 600; }
.main-content table th, .main-content table td { padding: 11px 16px; }
.main-content table tr:nth-child(even) td { background: var(--secondary); }
.main-content table code { white-space: nowrap; }
.main-content blockquote p:last-child { margin-bottom: 0; }
.site-footer { margin-top: 48px; padding-top: 24px; font-size: 13px; }
.site-footer-owner { color: var(--foreground); }
.home-page .main-content { background: transparent; border: 0; box-shadow: none; }
@media (max-width: 920px) {
  .main-content { margin: 28px 24px 48px; padding: 36px; }
}
@media (max-width: 650px) {
  .page-header { padding: 18px 20px !important; flex-wrap: wrap; }
  .page-header .project-name { font-size: 16px !important; }
  .site-actions { margin-left: auto; }
  .main-content { margin: 20px 12px 36px; padding: 26px 20px; font-size: 15px; border-radius: 12px; }
  .main-content h1 { padding-right: 0; font-size: 26px; }
  .main-content h2 { font-size: 21px; margin-top: 34px; }
  .main-content .code-window pre { padding: 16px !important; }
  .home-page .main-content h1 { padding-right: 36px; }
}
