/* ==========================================================================
   Zen Architecture v9 - Core Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Reset & Variables
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

:root {
  --mg-f-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mg-f-serif: var(--mg-f-sans);
  --mg-f-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --mg-w-black: 900;
  --mg-w-bold: 600;
  --mg-w-medium: 500;
  --mg-w-normal: 400;
  --mg-w-light: 300;

  --primary-color: rgb(221, 76, 79);
  --mg-t-p: #292524;
  --mg-t-s: #303030;
  --mg-border: #383838;
  --mg-bg-code: rgba(221, 76, 79, 0.2);
  --background: #f5f0eb;

  --content-max-width: 800px;
  --border-radius: 2px;
  --transition-duration: 0.3s;

  --mg-fs-p: 16px;
  --mg-fs-h2: 24px;
  --mg-fs-h3: 22px;
  --mg-fs-h4: 20px;
  --mg-fs-h5: 18px;
  --mg-fs-h6: 16px;
  --mg-fs-table: 14px;
  --mg-fs-code: 0.9em;
}

html.dark-theme {
  --primary-color: rgb(221, 76, 79);
  --mg-t-p: #d0cac4;
  --mg-t-s: #bcbcbc;
  --mg-border: #6d6d6d;
  --mg-bg-code: rgba(221, 76, 79, 0.5);
  --background: #0a0a0a;
}

body {
  font-family: var(--mg-f-serif);
  font-weight: var(--mg-w-normal);
  line-height: 1.64;
  -webkit-font-smoothing: antialiased;
  background-color: var(--background);
  color: var(--mg-t-p);
  transition: background-color var(--transition-duration);
}

@media (max-width: 768px) {
  :root {
    --mg-fs-p: 16px;
    --mg-fs-h2: 21px;
    --mg-fs-h3: 19px;
    --mg-fs-h4: 18px;
    --mg-fs-h5: 17px;
    --mg-fs-h6: 16px;
    --mg-fs-table: 14px;
    --mg-fs-code: 0.9em;
  }

  body {
    line-height: 1.55;
  }
}

/* --------------------------------------------------------------------------
   2. Layout & Typography
   -------------------------------------------------------------------------- */
.page-header {
  width: 100%;
  margin-block: 20px;
  box-sizing: border-box;
}

.header-inner {
  max-inline-size: var(--content-max-width);
  margin-inline: auto;
  padding-inline: 15px;
  display: flex;
  align-items: center;
  gap: 25px;
  width: 100%;
}

.page-header_title {
  flex: 1;
  min-inline-size: 0;
  font-size: min(6vw, 40px);
  font-family: var(--mg-f-serif);
  font-weight: var(--mg-w-black);
  margin: 0;
  color: var(--mg-t-p);
}

.page-header_title a {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 15px;
}

.nav-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
  border-radius: 2px;
  aspect-ratio: 1 / 1;
}

@media (max-width: 768px) {
  .nav-logo {
    height: 30px;
  }
}

.page-footer {
  font-size: 12px;
  width: 100%;
  margin-block: 40px 30px;
  box-sizing: border-box;
  font-family: var(--mg-f-serif);
  color: var(--mg-t-s);
}

.footer-inner {
  max-inline-size: var(--content-max-width);
  margin-inline: auto;
  padding-inline: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.footer-links a {
  text-decoration: none;
  color: inherit;
  transition: color var(--transition-duration);
}

.footer-links a:hover {
  color: var(--primary-color);
}

.footer-links .underline {
  text-decoration: underline;
}

.back-to-top {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-duration);
  opacity: 0.8;
}

.back-to-top:hover {
  opacity: 1;
  transform: translateY(-3px);
}

/* --------------------------------------------------------------------------
   3. Theme Toggle & UI Components
   -------------------------------------------------------------------------- */
.theme-toggle {
  position: relative;
  display: flex;
  align-items: center;
}

.theme-toggle input {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

.theme-toggle label {
  position: relative;
  display: block;
  width: 40px;
  height: 22px;
  border-radius: 12px;
  flex-shrink: 0;
  background-color: rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

html.dark-theme .theme-toggle label {
  background-color: rgba(255, 255, 255, 0.15);
}

.theme-toggle_handle {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 18px;
  background-color: rgba(245, 240, 235, .86);
  transition: transform 0.2s ease;
}

html.dark-theme .theme-toggle_handle {
  background-color: rgba(0, 0, 0, .86);
}

.theme-toggle input:checked+label .theme-toggle_handle {
  transform: translate(18px);
}

.theme-toggle svg {
  position: absolute;
  fill: currentColor;
  top: 5px;
  width: 12px;
  height: 12px;
  z-index: 2;
  transition: color .15s linear;
  color: rgba(0, 0, 0, .82);
}

html.dark-theme .theme-toggle svg {
  color: rgba(255, 255, 255, .82);
}

.theme-toggle .sun {
  left: 5px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.theme-toggle .moon {
  right: 5px;
}

.search-button {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--mg-t-p);
  transition: color var(--transition-duration);
  min-width: 30px;
  min-height: 30px;
}

.search-button:hover,
.search-button.active {
  color: var(--primary-color);
}

.search-button svg {
  width: 20px;
  height: 20px;
}

/* --------------------------------------------------------------------------
   4. Index & List Styles
   -------------------------------------------------------------------------- */
.content-list {
  max-inline-size: var(--content-max-width);
  margin-block: 20px;
  margin-inline: auto;
  padding-inline: 15px;
  width: 100%;
  list-style: none;
}

.content-item {
  margin-block: 15px;
}

.content-list-header {
  display: flex;
  align-items: center;
  gap: 15px;
}

.content-list-title {
  font-weight: var(--mg-w-normal);
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
  flex-shrink: 1;
  min-width: 0;
}

.content-list-title a {
  text-decoration: none;
  color: inherit;
}

.content-list-title a:hover {
  text-decoration: underline;
  text-decoration-color: var(--primary-color);
  text-underline-offset: 4px;
}

@media (max-width: 768px) {
  .content-list-title {
    font-size: 16px;
    line-height: 1.3;
  }
}

.content-time {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  font-family: var(--mg-f-mono);
  flex-shrink: 0;
  width: fit-content;
  line-height: 1.1;
}

.time-mmdd {
  font-size: 10px;
  font-weight: var(--mg-w-bold);
  display: block;
  text-align: center;
}

.time-yyyy {
  font-size: 10px;
  display: flex;
  justify-content: space-between;
  font-weight: var(--mg-w-normal);
}

/* --------------------------------------------------------------------------
   5. Content Pages (Article)
   -------------------------------------------------------------------------- */
.content-wrapper {
  max-inline-size: var(--content-max-width);
  margin-inline: auto;
  padding-inline: 15px;
  width: 100%;
}

.content-header {
  max-inline-size: var(--content-max-width);
  margin-block: 15px;
  margin-inline: auto;
}

.content-title {
  font-size: 28px;
  font-weight: var(--mg-w-bold);
  margin: 0;
  padding: 0;
  line-height: 1.4;
}

@media (max-width: 768px) {
  .content-title {
    font-size: 22px;
  }
}

.content-publish-time {
  color: var(--mg-t-s);
  font-size: 14px;
  font-weight: var(--mg-w-normal);
}

article {
  overflow-wrap: break-word;
  word-break: break-word;
}

article a {
  color: var(--mg-t-p);
  text-decoration-color: var(--primary-color);
}

article h1:not(.content-title),
article h2,
article h3,
article h4,
article h5,
article h6 {
  max-inline-size: var(--content-max-width);
  margin-inline: auto;
  line-height: 1.3;
  color: var(--mg-t-p);
}

article h2 {
  margin-block-start: 1.5em;
  font-size: var(--mg-fs-h2);
}

article h3 {
  margin-block-start: 1.4em;
  font-size: var(--mg-fs-h3);
}

article h4 {
  margin-block-start: 1.3em;
  font-size: var(--mg-fs-h4);
}

article h5 {
  margin-block-start: 1.25em;
  font-size: var(--mg-fs-h5);
}

article h6 {
  margin-block-start: 1.2em;
  font-size: var(--mg-fs-h6);
}

article p {
  max-inline-size: var(--content-max-width);
  margin-block: 1.1em;
  margin-inline: auto;
  font-size: var(--mg-fs-p);
  line-height: 1.7;
  color: var(--mg-t-p);
  text-align: justify;
}

article img {
  max-inline-size: 100%;
  height: auto;
  border-radius: 8px;
  vertical-align: middle;
}

/* 独立成行的媒体元素应用居中和边距 */
.figure-img img,
.figure-media .media,
.figure-img,
.figure-media,
.figure-iframe {
  display: block;
  margin-inline: auto;
  margin-block: 15px;
  max-inline-size: var(--content-max-width);
}

article hr {
  max-inline-size: var(--content-max-width);
  margin-block: 40px;
  margin-inline: auto;
  border: none;
}

article hr::after {
  content: "";
  display: block;
  block-size: 1px;
  background-color: var(--mg-border);
}

article blockquote {
  max-inline-size: var(--content-max-width);
  margin-block: 15px;
  margin-inline: auto;
  position: relative;
  font-style: italic;
  color: var(--mg-t-s);
}

article blockquote::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  inline-size: 3px;
  block-size: 100%;
  background-color: var(--primary-color);
}

article blockquote p {
  font-size: var(--mg-fs-p);
  padding: 0;
  margin-inline-start: 10px;
}

article ul,
article ol {
  max-inline-size: var(--content-max-width);
  padding-inline-start: 2em;
  margin-block: 15px;
  margin-inline: auto;
  color: var(--mg-t-p);
  font-size: var(--mg-fs-p);
  line-height: 1.5;
  text-align: justify;
}

article ul li::marker,
article ol li::marker {
  color: var(--primary-color);
}

article ul li,
article ol li {
  margin-block: 5px;
}

article li p {
  margin-block: 5px;
  padding-inline: 0;
}

.table-container {
  max-inline-size: var(--content-max-width);
  margin-block: 15px;
  margin-inline: auto;
  overflow-x: auto;
}

article table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--mg-fs-table);
  color: var(--mg-t-p);
}

article table th,
article table td {
  padding: 10px 14px;
  border: 1px solid var(--mg-border);
  text-align: left;
}

article table th {
  background-color: var(--mg-bg-code);
  font-weight: var(--mg-w-medium);
}

article table tr:nth-child(even) {
  background-color: rgba(128, 128, 128, 0.05);
}

/* 页面各种媒体容器的通用布局规则 */

html.dark-theme img {
  filter: brightness(0.85);
  transition: filter var(--transition-duration);
}

.figure-iframe iframe:not([width]):not([height]) {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 320px;
  border: 1px solid var(--mg-border);
  border-radius: var(--border-radius);
}

.figure-iframe iframe[width],
.figure-iframe iframe[height] {
  display: inline;
  border: none;
  border-radius: 0;
}

article figcaption {
  font-size: 12px;
  color: var(--mg-t-s);
  text-align: center;
  margin-block-start: 5px;
}

strong {
  font-weight: var(--mg-w-bold);
}

.content-actions {
  max-inline-size: var(--content-max-width);
  display: flex;
  align-items: center;
  margin-block: 40px;
  margin-inline: auto;
  font-size: 14px;
}

.content-actions__item:not(:last-child)::after {
  content: "·\00a0";
}

.content-actions__item>a {
  color: inherit;
  text-decoration-color: var(--primary-color);
}

@media (max-width: 520px) {
  .content-actions {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .content-actions__item:not(:last-child)::after {
    content: "";
  }
}

/* --------------------------------------------------------------------------
   6. Code Rendering (Shiki)
   -------------------------------------------------------------------------- */
article pre.shiki-block {
  background: #1a1b26 !important;
  /* Tokyo Night background */
  border: 1px solid var(--mg-border);
  border-radius: 8px;
  padding: 0.5em;
  margin-block: 1em;
  width: 100%;
  overflow: auto;
  font-family: var(--mg-f-mono);
  font-size: var(--mg-fs-code);
  line-height: 1.6;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  position: relative; /* 为复制按钮定位 */
}

article pre.shiki-block::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.copy-code-button {
  position: absolute;
  top: 5px;
  right: 5px;
  padding: 2px 8px;
  font-size: 10px;
  color: var(--mg-t-s);
  background: #1a1b26; /* 使用不透明背景遮挡代码 */
  border: 1px solid var(--mg-border);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 10;
  font-family: var(--mg-f-sans);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); /* 增加投影增强层级感 */
}

article pre.shiki-block:hover .copy-code-button {
  opacity: 1;
}

.copy-code-button:hover {
  background: #24283b; /* 悬浮时稍微亮一点 */
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.copy-code-button.success {
  color: #10b981; /* 成功绿色 */
  border-color: #10b981;
}

article pre.shiki-block code {
  font-size: 1em;
  text-shadow: none !important;
  background: transparent !important;
}

article :not(pre)>code {
  font-family: var(--mg-f-mono);
  font-size: 0.85em;
  background-color: var(--mg-bg-code);
  color: var(--mg-t-p);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}

pre.shiki-block::-webkit-scrollbar {
  height: 6px;
  width: 6px;
}

pre.shiki-block::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.2);
  border-radius: 10px;
}

pre.shiki-block::-webkit-scrollbar-thumb:hover {
  background: rgba(128, 128, 128, 0.4);
}

/* --------------------------------------------------------------------------
   7. Admonitions (GitHub Style)
   -------------------------------------------------------------------------- */
article .admonition {
  padding: 8px;
  margin-block: 1.5em;
  border-left: 4px solid;
  border-radius: 6px;
  background-color: rgba(128, 128, 128, 0.05);
}

article .admonition::before {
  display: none;
}

/* Override default blockquote bar */

article .admonition-title {
  font-weight: var(--mg-w-bold);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  font-size: 0.85em;
  letter-spacing: 0.05em;
}

article .admonition-note {
  border-left-color: #0969da;
  background-color: rgba(9, 105, 218, 0.05);
}

article .admonition-note .admonition-title {
  color: #0969da;
}

article .admonition-tip {
  border-left-color: #1a7f37;
  background-color: rgba(26, 127, 55, 0.05);
}

article .admonition-tip .admonition-title {
  color: #1a7f37;
}

article .admonition-important {
  border-left-color: #8250df;
  background-color: rgba(130, 80, 223, 0.05);
}

article .admonition-important .admonition-title {
  color: #8250df;
}

article .admonition-warning {
  border-left-color: #9a6700;
  background-color: rgba(154, 103, 0, 0.05);
}

article .admonition-warning .admonition-title {
  color: #9a6700;
}

article .admonition-caution {
  border-left-color: #cf222e;
  background-color: rgba(207, 34, 46, 0.05);
}

article .admonition-caution .admonition-title {
  color: #cf222e;
}

article .admonition p {
  margin-block: 8px;
  padding: 0 !important;
  margin-inline-start: 0 !important;
}

/* --------------------------------------------------------------------------
   7. TOC (Table of Contents)
   -------------------------------------------------------------------------- */
.toc-container {
  position: fixed;
  left: calc(50% + 400px);
  top: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  width: 200px;
  z-index: 1000;
  pointer-events: none;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s ease;
  transform: translateX(10px) scale(0.98);
  pointer-events: auto;
  max-height: 85vh;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.toc-list::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.toc-container:hover .toc-list {
  opacity: 1;
  visibility: visible;
  transform: translateX(0) scale(1);
}

.desktop-toc-dots {
  position: absolute;
  left: -15px;
  width: 30px;
  height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
  pointer-events: auto;
  cursor: pointer;
}

.toc-container:hover .desktop-toc-dots {
  opacity: 0;
  visibility: hidden;
}

.toc-link {
  display: block;
  color: var(--mg-t-s);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 16em;
  transition: all 0.2s ease;
}

.toc-item.is-active .toc-link,
.toc-link:hover {
  color: var(--primary-color) !important;
  font-weight: 500;
  opacity: 1 !important;
}

.toc-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--mg-t-p);
  opacity: 0.3;
  transition: all 0.1s ease;
}

.toc-dot.is-active {
  background: var(--primary-color);
  opacity: 1;
  box-shadow: 0 0 8px rgba(221, 76, 79, 0.7);
}

.mobile-toc-trigger {
  display: none;
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  padding-right: 6px;
  gap: 6px;
  z-index: 1500;
  cursor: pointer;
}

.mobile-toc-overlay {
  position: fixed;
  inset: 0;
  background: var(--background);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  overscroll-behavior: contain;
}

html.dark-theme .mobile-toc-overlay {
  background: var(--background);
}

.mobile-toc-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

body.lock-scroll {
  overflow: hidden;
}

.mobile-toc-dial {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 30px 100px;
  box-sizing: border-box;
  scrollbar-width: none;
}

.mobile-toc-dial::-webkit-scrollbar {
  display: none;
}

.mobile-toc-item {
  min-height: 26px;
  display: flex;
  width: 100%;
}

.mobile-toc-link {
  color: var(--mg-t-p);
  opacity: 0.7;
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.mobile-toc-item.is-active .mobile-toc-link {
  color: var(--primary-color);
  opacity: 1;
  font-weight: 500;
}

@media (max-width: 1250px) {
  .toc-container {
    display: none;
  }

  .mobile-toc-trigger {
    display: flex;
  }
}

/* --------------------------------------------------------------------------
   8. Search Page
   -------------------------------------------------------------------------- */
.search-container {
  max-inline-size: var(--content-max-width);
  margin-block: 40px;
  margin-inline: auto;
  padding-inline: 15px;
}

.search-input {
  width: 100%;
  padding: 10px 15px;
  font-size: 16px;
  border: 2px solid var(--mg-border);
  border-radius: 8px;
  background-color: var(--background);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.search-results {
  margin-top: 30px;
}

#searchResults {
  padding: 0;
  margin: 0;
}

.search-result-item {
  list-style: none;
  margin-block: 10px;
  padding: 10px;
  border-radius: 8px;
  transition: background-color var(--transition-duration);
}

.search-result-item:hover {
  background-color: var(--mg-bg-code);
}

.search-result-title {
  font-weight: var(--mg-w-bold);
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.search-result-title a {
  text-decoration: none;
  color: inherit;
}

.search-result-meta {
  font-size: 12px;
  color: var(--mg-t-s);
  margin-top: 5px;
  opacity: 0.8;
}

.search-result-description {
  margin-top: 6px;
  font-size: 14px;
  color: var(--mg-t-s);
  line-height: 1.5;
}

.search-result-description {
  margin-top: 8px;
  font-size: 14px;
  color: var(--mg-t-s);
  line-height: 1.5;
}

.search-result-time {
  display: inline-block;
  font-size: 12px;
  color: var(--mg-t-s);
}

.no-results {
  text-align: center;
  color: var(--mg-t-s);
  margin-top: 60px;
}

.search-highlight {
  background-color: var(--mg-bg-code);
  color: inherit;
  padding: 1px 2px;
  border-radius: 2px;
}

.keywords-area {
  margin-top: 30px;
  margin-bottom: 20px;
}

.keywords-list {
  display: flex;
  flex-wrap: wrap;
  gap: 15px 10px;
  align-items: center;
}

.keyword-tag {
  font-size: 14px;
  color: var(--mg-t-p);
  cursor: pointer;
  transition: color var(--transition-duration);
}

.keyword-tag:hover,
.keyword-tag.active {
  color: var(--primary-color);
  font-weight: var(--mg-w-bold);
}

.keyword-tag.hidden {
  display: none;
}

/* Fix for nested figures from legacy manual markdown */
figure figure {
  margin: 0 !important;
  padding: 0 !important;
}

