/* ---------------------------------------------------------------
 * 技术笔记 · 站点样式
 * 视觉基调取自 Typecho 默认主题：白底、衬线正文、#3354AA 链接、
 * #F3F3F3 代码块、#EEE 分隔线；布局改为 VuePress 式三栏。
 * --------------------------------------------------------------- */

:root {
  --bg: #fff;
  --text: #444;
  --muted: #999;
  --border: #eee;
  --border-strong: #ddd;
  --link: #3354AA;
  --link-hover: #444;
  --panel: #F6F6F6;
  --code-bg: #F3F3F3;
  --code-inline: #B94A48;
  --sidebar-w: 268px;
  --toc-w: 210px;
  --header-h: 58px;
  --font-serif: "Droid Serif", Georgia, "Times New Roman", "PingFang SC", "Hiragino Sans GB", "Source Han Sans CN", "WenQuanYi Micro Hei", "Microsoft Yahei", serif;
  --font-sans: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif;
  --font-mono: Menlo, Monaco, Consolas, "Lucida Console", "Courier New", monospace;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover, a:active { color: var(--link-hover); }

/* ---------------- 顶栏 ---------------- */

#header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: saturate(180%) blur(6px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

#logo {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: #333;
  letter-spacing: .5px;
  white-space: nowrap;
}

#top-nav {
  display: flex;
  gap: 18px;
  font-family: var(--font-sans);
  font-size: .85rem;
}

#top-nav a { color: #555; }
#top-nav a:hover { color: var(--link); }

#search { margin-left: auto; position: relative; }

#search input {
  width: 240px;
  padding: 6px 12px;
  border: 1px solid #E9E9E9;
  border-radius: 2px;
  background: #fff;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: .85rem;
  outline: none;
  transition: border-color .15s ease;
}

#search input:focus { border-color: #c9d4e8; }

#search-result {
  position: absolute;
  right: 0;
  top: 116%;
  width: min(420px, 86vw);
  max-height: 62vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .07);
  font-family: var(--font-sans);
}

#search-result .item {
  display: block;
  padding: 9px 14px;
  border-bottom: 1px solid #f5f5f5;
  color: #333;
  font-size: .86rem;
  line-height: 1.5;
}

#search-result .item:last-child { border-bottom: 0; }
#search-result .item:hover,
#search-result .item.active { background: var(--panel); color: var(--link); }
#search-result .item .meta { display: block; color: var(--muted); font-size: .76rem; }
#search-result .empty { padding: 14px; color: var(--muted); font-size: .85rem; }
#search-result mark { background: #fff3c4; color: inherit; padding: 0 1px; }

#menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: #fff;
  color: #444;
  font-size: 1rem;
  line-height: 1;
  padding: 6px 9px;
  border-radius: 2px;
  cursor: pointer;
}

/* ---------------- 三栏骨架 ---------------- */

.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 40px;
  align-items: start;
}

/* ---------------- 侧边目录 ---------------- */

#sidebar {
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 22px 4px 48px 0;
  font-family: var(--font-sans);
  font-size: .85rem;
  scrollbar-width: thin;
}

#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-thumb { background: #e6e6e6; border-radius: 3px; }

.side-area { margin-bottom: 10px; }

.side-area > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 2px;
  color: #8a8a8a;
  font-size: .74rem;
  letter-spacing: .1em;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.side-area > summary::-webkit-details-marker { display: none; }

.side-area > summary::before {
  content: "▸";
  color: #ccc;
  font-size: .68rem;
  transform: translateY(-1px);
  transition: transform .15s ease;
}

.side-area[open] > summary::before { transform: rotate(90deg) translateY(1px); }
.side-area > summary:hover { background: var(--panel); color: #555; }

.side-area > summary .area-name { color: inherit; }
.side-area > summary .area-count { margin-left: auto; color: #ccc; font-size: .7rem; }

.side-area > .side-tut { margin-left: 6px; }

.side-tut > summary.current { color: var(--link); }

.side-tut { margin: 0; }

.side-tut > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 2px;
  color: #333;
  font-size: .87rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.side-tut > summary::-webkit-details-marker { display: none; }

.side-tut > summary::before {
  content: "▸";
  color: #bbb;
  font-size: .7rem;
  transform: translateY(-1px);
  transition: transform .15s ease;
}

.side-tut[open] > summary::before { transform: rotate(90deg) translateY(1px); }
.side-tut > summary:hover { background: var(--panel); }

.side-tut .tut-count {
  margin-left: auto;
  color: #c4c4c4;
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
}

.side-tut ul {
  margin: 2px 0 8px;
  padding: 0 0 0 8px;
  list-style: none;
}

.side-tut li a {
  display: block;
  padding: 4px 8px 4px 14px;
  border-left: 2px solid transparent;
  color: #555;
  font-size: .82rem;
  line-height: 1.55;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-tut li a:hover { background: var(--panel); color: var(--link); }

.side-tut li a.active {
  border-left-color: var(--link);
  background: var(--panel);
  color: var(--link);
}

/* ---------------- 正文 ---------------- */

#main { padding: 26px 0 72px; min-width: 0; }

.breadcrumb {
  font-family: var(--font-sans);
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--link); }
.breadcrumb i { margin: 0 6px; font-style: normal; color: #ccc; }
.breadcrumb b { font-weight: normal; color: #777; }

.post-title {
  margin: 0 0 22px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.35;
  color: #333;
}

.post-content { font-size: 16px; line-height: 1.8; }

.post-content > *:first-child { margin-top: 0; }

.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
  font-family: var(--font-sans);
  color: #333;
  line-height: 1.45;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.post-content h2 {
  margin: 2.4em 0 .9em;
  padding-bottom: .4em;
  border-bottom: 1px solid #f1f1f1;
  font-size: 1.35rem;
}

.post-content h3 { margin: 1.9em 0 .7em; font-size: 1.12rem; }
.post-content h4 { margin: 1.6em 0 .6em; font-size: 1rem; }

.post-content p { margin: .95em 0; }
.post-content ul, .post-content ol { margin: .9em 0; padding-left: 1.7em; }
.post-content li { margin: .35em 0; }
.post-content li > ul, .post-content li > ol { margin: .3em 0; }

.post-content hr {
  margin: 2.2em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.post-content strong { color: #333; }

/* 链接沿用 Typecho 的下划线式提示 */
.post-content a { border-bottom: 1px solid #eaeaea; }
.post-content a:hover { border-bottom-color: transparent; }

/* 代码 */
.post-content code {
  padding: 2px 4px;
  background: var(--code-bg);
  border-radius: 2px;
  color: var(--code-inline);
  font-family: var(--font-mono);
  font-size: .9em;
  word-break: break-word;
}

.post-content pre,
.post-content .highlight {
  margin: 1.2em 0;
  padding: 12px 14px;
  background: var(--code-bg);
  border-radius: 3px;
  overflow: auto;
  line-height: 1.6;
}

.post-content pre code {
  padding: 0;
  background: none;
  color: #3d3d3d;
  font-size: .86em;
}

.post-content .highlight pre { margin: 0; padding: 0; background: none; }

/* 引用 */
.post-content blockquote {
  margin: 1.3em 0;
  padding: .2em 0 .2em 1.3em;
  border-left: 4px solid #eee;
  color: #666;
}

.post-content blockquote p { margin: .5em 0; }

/* 表格 */
.post-content .table-wrap {
  margin: 1.3em 0;
  overflow-x: auto;
}

.post-content table {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-collapse: collapse;
  font-size: .93em;
}

.post-content th,
.post-content td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.post-content th { background: var(--code-bg); font-family: var(--font-sans); font-weight: 600; }

/* 图片 */
.post-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.4em auto;
  border-radius: 2px;
}

/* 上一篇 / 下一篇 */
.post-near {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 56px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
}

.near-link { max-width: 46%; display: flex; flex-direction: column; gap: 3px; }
.near-next { margin-left: auto; text-align: right; }
.near-label { color: var(--muted); font-size: .74rem; letter-spacing: .06em; }
.near-title { font-size: .88rem; color: var(--link); }
.near-link:hover .near-title { text-decoration: underline; }
.near-empty { flex: 1; }

/* ---------------- 本页目录 ---------------- */

#toc {
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 26px 0 40px;
  font-family: var(--font-sans);
  font-size: .8rem;
}

.toc-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: .12em;
}

#toc-list { margin: 0; padding: 0; list-style: none; border-left: 1px solid var(--border); }

#toc-list li { margin: 0; }

#toc-list a {
  display: block;
  padding: 3px 0 3px 10px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: #777;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#toc-list a:hover { color: var(--link); }

#toc-list a.active {
  border-left-color: var(--link);
  color: var(--link);
}

#toc-list .lv3 a { padding-left: 22px; font-size: .77rem; color: #8a8a8a; }

/* ---------------- 首页 ---------------- */

.hero { margin: 4px 0 26px; }
.hero h2 { margin: 0 0 6px; font-family: var(--font-sans); font-size: 1.5rem; color: #333; font-weight: 600; }
.hero p { margin: 0; color: #777; font-size: .92rem; }

.cards { margin: 34px 0; }

.cards h2 {
  margin: 0 0 14px;
  padding-bottom: .35em;
  border-bottom: 1px solid #f1f1f1;
  font-family: var(--font-sans);
  font-size: 1.15rem;
  color: #333;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fff;
  transition: border-color .15s ease, background .15s ease;
}

.card:hover { border-color: #dcdcdc; background: #fbfbfb; }
.card-tut { font-family: var(--font-sans); font-size: .95rem; color: #333; }
.card:hover .card-tut { color: var(--link); }
.card-meta { color: var(--muted); font-size: .76rem; font-family: var(--font-sans); }

/* ---------------- 遮罩与响应式 ---------------- */

#backdrop {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0;
  background: rgba(0, 0, 0, .28);
  z-index: 30;
}

@media (max-width: 1100px) {
  :root { --toc-w: 0px; }
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 32px; }
  #toc { display: none; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 18px; }
  #menu-toggle { display: inline-block; }
  #top-nav { display: none; }

  #sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: 281px;
    max-height: none;
    margin: 0;
    padding: 18px 14px 40px;
    background: #fff;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 35;
  }

  body.nav-open #sidebar { transform: none; }
  body.nav-open #backdrop { display: block; }

  #search input { width: 150px; }
  #search-result { width: min(340px, 90vw); }
  .post-title { font-size: 1.5rem; }
  .post-content { font-size: 15px; }
}

@media (max-width: 520px) {
  .header-inner { gap: 12px; padding: 0 14px; }
  #logo { font-size: 1.1rem; }
  #search input { width: 120px; }
  .post-near { flex-direction: column; }
  .near-link { max-width: 100%; }
  .near-next { margin-left: 0; text-align: left; }
}

/* 打印 */
@media print {
  #header, #sidebar, #toc, .post-near, #backdrop { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; }
  .post-title { border: 0; }
  .post-content a { color: #000; border: 0; }
}

/* 可访问性 */
:focus-visible { outline: 2px solid #b9c7e6; outline-offset: 2px; }

/* ---------------- 交互演示内嵌 ---------------- */

.demo-embed {
  margin: 1.6em 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
}

.demo-embed-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: .8rem;
  color: #555;
}

.demo-embed-head a { font-size: .78rem; }
.demo-embed iframe { display: block; width: 100%; height: 700px; border: 0; background: #fff; }

@media (max-width: 720px) {
  .demo-embed iframe { height: 660px; }
}

/* ---------------- 交互演示入口卡片 ---------------- */

.demo-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 1.4em 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--link);
  border-radius: 3px;
  background: #fbfcff;
}

.demo-card-body { display: flex; flex-direction: column; gap: 3px; }
.demo-card-body strong { font-family: var(--font-sans); font-size: .95rem; color: #333; font-weight: 600; }
.demo-card-body span { font-size: .82rem; color: var(--muted); }

.demo-btn {
  flex: none;
  padding: 7px 14px;
  border-radius: 3px;
  background: var(--link);
  color: #fff;
  font-family: var(--font-sans);
  font-size: .84rem;
  white-space: nowrap;
  border-bottom: 0 !important;
}

.demo-btn:hover { background: #2a4690; color: #fff; }

@media (max-width: 640px) {
  .demo-card { flex-direction: column; align-items: flex-start; }
}

/* ---- 方是方，圆是圆 ---- */
#search input, #search-result, #search-result .item, .demo-card, .demo-btn,
.post-content pre, .post-content .highlight, .post-content pre code,
.post-content table, .post-content th, .post-content td,
.card, .hero, .detail-box, .tag, .badge, .chip,
#toc-list a, .side-tut li a, .breadcrumb b { border-radius: 0 !important; }
.demo-card { border-left-width: 3px; }
