:root {
  color-scheme: light;
  --bg: #fff;
  --paper: #f7f6ef;
  --text: rgba(36, 41, 47, 0.9);
  --muted: rgba(85, 85, 85, 0.78);
  --line: #e7e8e5;
  --accent: #5d46a8;
  --accent-soft: #f7f4ff;
  --header: #15141a;
  --header-text: #ffffff;
  --link: rgba(36, 41, 47, 0.82);
  --nav-bg: #fff;
  --nav-shadow: rgba(0, 0, 0, 0.1);
  --nav-text: rgba(36, 41, 47, 0.76);
  --strong: rgba(0, 0, 0, 0.9);
  --strong-soft: rgba(0, 0, 0, 0.84);
  --hover: #15141a;
  --link-line: rgba(36, 41, 47, 0.22);
  --panel: #ffffff;
  --chip-bg: rgba(247, 246, 239, 0.72);
  --code-border: #e1d9f7;
  --max-width: 900px;
  --read-width: 760px;
  --post-width: 1080px;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif-font: "TsangerJinKai02", "STKaiti", "KaiTi", var(--ui-font);
  --mono-font: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111116;
  --paper: #1b1a22;
  --text: rgba(244, 241, 236, 0.9);
  --muted: rgba(215, 210, 202, 0.66);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #c4b5fd;
  --accent-soft: rgba(196, 181, 253, 0.14);
  --header: #0d0d12;
  --header-text: #f8f5ef;
  --link: rgba(236, 230, 220, 0.86);
  --nav-bg: #15141a;
  --nav-shadow: rgba(0, 0, 0, 0.38);
  --nav-text: rgba(244, 241, 236, 0.74);
  --strong: rgba(255, 255, 255, 0.92);
  --strong-soft: rgba(244, 241, 236, 0.82);
  --hover: #ffffff;
  --link-line: rgba(244, 241, 236, 0.28);
  --panel: #1a1920;
  --chip-bg: rgba(255, 255, 255, 0.07);
  --code-border: rgba(196, 181, 253, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  text-size-adjust: 100%;
}

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

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.site-header {
  background: transparent;
  color: var(--text);
  overflow: hidden;
}

/* ── Navigation (matches tw93) ── */
.header-menu {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 20;
  background: var(--nav-bg);
  height: 60px;
  box-shadow: 0 0 0 0, 0 6px 12px var(--nav-shadow);
  padding: 0 15px;
}

.header-menu ul {
  margin: 0 auto;
  list-style: none;
  height: 100%;
  padding: 0;
}

@media (min-width: 768px) {
  .header-menu {
    position: fixed;
    padding: 0;
    transition: transform 0.3s ease-out;
  }
}

@media (min-width: 1000px) {
  .header-menu ul {
    max-width: 900px;
    padding: 0;
  }
}

.header-menu-overflow {
  transform: translateY(-100%);
}

.header-item-container {
  height: 100%;
  display: flex;
  align-items: center;
}

.header-item {
  height: 100%;
  display: flex;
  align-items: center;
  padding-left: 8px;
  padding-right: 8px;
}

.header-item a {
  display: block;
  font-size: 15px;
  font-weight: bold;
  color: var(--nav-text);
  vertical-align: middle;
}

.header-item.active a,
.header-item:hover a {
  color: var(--strong);
}

.header-item-title {
  border-top-width: 0;
  padding-left: 0;
  padding-right: 20px;
}

.search-btn-container {
  margin-left: auto;
}

.header-item-title a.title {
  font-size: 24px;
  font-weight: 800;
  color: var(--strong);
  display: flex;
  align-items: center;
  height: 60px;
}

@media (min-width: 768px) {
  .header-item-title a.title {
    font-size: 30px;
  }
  .header-item a {
    font-size: 16px;
  }
}

.header-item-left {
  display: flex;
  align-items: center;
  padding-left: 10px;
  padding-right: 10px;
}

.header-item-left:first-of-type {
  display: none;
}

@media (min-width: 768px) {
  .header-item-left:first-of-type {
    display: flex;
  }
}

.search-btn,
.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease;
}

.search-btn:hover,
.theme-toggle-btn:hover {
  color: var(--strong);
  background: var(--chip-bg);
}

.entry-header {
  position: relative;
  height: 260px;
  display: grid;
  place-items: center;
  background: var(--header);
  background-repeat: no-repeat;
  background-size: cover;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.entry-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
}

body#home .entry-header,
body#post-index .entry-header {
  height: 340px;
  background-image: url("../images/site/home-hero.png");
  background-position: center 42%;
  background-repeat: no-repeat;
  background-size: cover;
}

body#home .entry-header::before,
body#post-index .entry-header::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(11, 18, 32, 0.08));
}

body#post .entry-header.has-image,
body#page .entry-header.has-image {
  height: 340px;
}

body#post .entry-header.has-image::before,
body#page .entry-header.has-image::before {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.08));
}

.entry-header .header-title {
  position: relative;
  z-index: 1;
  width: min(var(--max-width), calc(100% - 32px));
  margin: 0 auto;
  color: var(--header-text);
  font-size: 36px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  letter-spacing: 1.2px;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.38);
}

body#home .entry-header .header-title,
body#post-index .entry-header .header-title,
.entry-header.has-image .header-title {
  display: none;
}

.entry-header canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.45;
}

body#home .entry-header canvas,
body#post-index .entry-header canvas,
.entry-header.has-image canvas {
  display: none;
}

#main {
  width: min(var(--read-width), calc(100% - 32px));
  margin: 46px auto 76px;
}

body#post,
body#page {
  background: var(--paper);
}

body#post #main,
body#page #main {
  width: auto;
  margin: 0;
}

@media (min-width: 768px) {
  body#post #main,
  body#page #main {
    margin: 0;
    background: transparent;
  }
}

/* ── Home page post list (matches tw93 #post-index) ── */
body#post-index {
  background: var(--paper);
}

#post-index #main {
  width: auto;
  margin: 60px 0 0 0;
  overflow: hidden;
  background: var(--paper);
}

#post-index article {
  background: var(--panel);
  box-shadow: none;
  margin-top: 15px;
  margin-bottom: 15px;
  padding: 15px;
}

@media (min-width: 768px) {
  #post-index #main {
    margin: 20px;
    background: transparent;
  }
  #post-index article {
    margin-top: 0;
    margin-bottom: 30px;
    border-radius: 8px;
    padding: 20px 36px;
  }
}

@media (min-width: 1000px) {
  #post-index #main {
    max-width: 900px;
    margin: 34px auto 0;
  }
  #post-index article {
    margin-bottom: 34px;
    padding: 30px 50px 20px;
  }
}

.header-href {
  display: block;
}

.entry-title {
  margin: 0 0 6px;
  color: var(--strong);
  font-size: 22px;
  line-height: 1.35;
  font-weight: 700;
  transition: color 160ms ease;
}

@media (min-width: 768px) {
  .entry-title {
    font-size: 30px;
  }
}

.header-href:hover .entry-title {
  color: var(--accent);
}

.entry-content span {
  color: var(--strong-soft);
  font-variant-numeric: tabular-nums;
}

.entry-content .page-info {
  margin: 0 0 34px;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.post-shell {
  position: relative;
}

.entry-content {
  font-size: 17px;
  text-autospace: ideograph-alpha ideograph-numeric;
  word-wrap: break-word;
}

/* Card styling only for article pages (matches tw93: #post / #page) */
#post .entry-content,
#page .entry-content {
  margin-bottom: 15px;
  padding: 10px 15px;
  background: var(--panel);
}

@media (min-width: 768px) {
  #post .entry-content,
  #page .entry-content {
    max-width: 900px;
    margin: 34px auto;
    padding: 32px 50px 70px;
    border-radius: 8px;
  }
  #post .entry-content > p:first-of-type,
  #page .entry-content > p:first-of-type {
    font-size: 20px;
  }
}

@media (min-width: 1000px) {
  #post .entry-content,
  #page .entry-content {
    padding: 32px 80px 70px;
  }
}

.post-toc {
  display: none;
}

.post-toc-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 4px 0 0;
}

.post-toc[hidden] {
  display: none;
}

/* Mobile: TOC shown above content as collapsible block */
@media (max-width: 640px) {
  .has-post-toc .post-toc {
    display: block;
  }
}

/* Medium: hide TOC (matches tw93 — only show on wide screens) */

.post-toc h2 {
  margin: 0 0 12px;
  color: var(--strong-soft);
  font-size: 16px;
  line-height: 1.4;
}

.post-toc ol {
  display: grid;
  gap: 7px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-toc a {
  display: block;
  padding: 6px 6px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.28;
  text-decoration: none;
  transition: color 160ms ease, background-color 160ms ease;
}

.post-toc a:hover {
  color: var(--header);
  background: var(--chip-bg);
}

.post-toc a.is-active {
  color: var(--header);
  font-weight: 700;
}

.post-toc .toc-level-3 {
  padding-left: 16px;
  font-size: 14px;
  font-weight: 500;
}

.post-toc .toc-level-4 {
  padding-left: 32px;
  font-size: 13px;
  font-weight: 500;
}

.post-title {
  margin: 6px 0 10px;
  color: var(--strong);
  font-size: 30px;
  line-height: 1.35;
  font-weight: 700;
}

.page-info {
  margin: 0 0 34px;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.post-cover {
  width: 100%;
  aspect-ratio: 16 / 7;
  margin: 0 auto 34px;
  overflow: hidden;
  border-radius: 8px;
  background-color: var(--paper);
  background-repeat: no-repeat;
  background-size: cover;
  box-shadow: 0 12px 34px rgba(21, 20, 26, 0.09);
}

/* Wide screen: TOC on the right side */
@media (min-width: 1408px) {
  .has-post-toc .post-shell {
    max-width: 900px;
    margin: 34px auto;
  }

  .has-post-toc .hentry {
    padding-top: 0;
  }

  .has-post-toc .entry-content {
    max-width: 900px;
    margin: 0 auto;
  }

  .has-post-toc .post-toc {
    display: block;
    position: absolute;
    top: -4px;
    left: calc(100% + 24px);
    width: 260px;
    height: 100%;
    min-height: 32px;
    border-left: 0;
    padding: 0;
  }

  .has-post-toc .post-toc-inner {
    position: sticky;
    top: 88px;
  }

  .has-post-toc .post-followup {
    max-width: 900px;
    margin: 0 auto;
  }
}

.entry-content a {
  color: var(--link);
  border-bottom: 1px solid var(--link-line);
}

.entry-content p,
.entry-content ul,
.entry-content ol,
.entry-content table {
  margin: 0 0 1.2em;
}

.entry-content h2 {
  margin-top: 2em;
  color: var(--strong);
  font-size: 25px;
  line-height: 1.35;
}

.entry-content h2,
.entry-content h3 {
  scroll-margin-top: 80px;
}

.has-post-toc .entry-content h2,
.has-post-toc .entry-content h3 {
  scroll-margin-top: 104px;
}

.entry-content h3 {
  margin-top: 1.6em;
  color: var(--strong-soft);
  font-size: 21px;
  line-height: 1.4;
}

.entry-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.2em auto;
  border-radius: 6px;
}

.entry-content mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 0.08em 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  user-select: text;
}

.entry-content mjx-container::-webkit-scrollbar {
  display: none;
}

.entry-content mjx-container[display="true"] {
  display: block;
  margin: 1.15em 0;
  padding: 0.3em 0;
  overflow-x: auto;
  text-align: center;
}

.math-copy-wrap {
  position: relative;
  margin: 1.15em 0;
  padding-right: 52px;
  user-select: text;
}

.math-copy-wrap mjx-container[display="true"] {
  margin: 0;
}

.math-copy-button {
  position: absolute;
  top: 8px;
  right: 0;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 160ms ease, color 160ms ease, border-color 160ms ease;
}

.math-copy-button svg {
  display: block;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.math-copy-button[data-copied="true"] {
  border-color: rgba(93, 70, 168, 0.36);
  color: var(--accent);
}

.math-copy-wrap:hover .math-copy-button,
.math-copy-button:focus-visible {
  opacity: 1;
}

.math-copy-button:hover,
.math-copy-button:focus-visible {
  border-color: rgba(93, 70, 168, 0.36);
  color: var(--accent);
  outline: 0;
}

.entry-content mjx-container:not([display="true"]) {
  display: inline-grid;
  max-width: 100%;
  vertical-align: -0.12em;
}

.entry-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 16px;
  line-height: 1.65;
}

.entry-content th,
.entry-content td {
  min-width: 120px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.entry-content th {
  background: var(--paper);
  color: var(--strong-soft);
  font-weight: 700;
}

.entry-content tr:nth-child(even) td {
  background: var(--chip-bg);
}

.entry-content code {
  font-family: var(--mono-font);
  padding: 0.08em 0.42em;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--code-border);
}

.archive-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin: 4px 0 34px;
}

.archive-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.01em;
  transition: color 0.15s;
}

.archive-tabs a:hover {
  color: var(--accent);
  box-shadow: none;
}

.archive-tabs em {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

.archive-groups {
  display: grid;
  gap: 42px;
}

.archive-group {
  scroll-margin-top: 22px;
}

.archive-group-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.archive-group-header h2 {
  margin: 0 0 4px;
  color: var(--strong);
  font-size: 28px;
  line-height: 1.35;
}

.archive-group-header p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.archive-group-header > span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
}

.archive-list {
  display: grid;
}

.archive-row {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 18px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.archive-row time {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.archive-row strong {
  display: block;
  color: var(--strong);
  font-size: 19px;
  line-height: 1.45;
}

.archive-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.archive-row:hover strong {
  color: var(--accent);
}

.archive-empty {
  margin: 0;
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 16px;
}

.site-footer {
  width: min(var(--max-width), calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.search-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 80px 16px 24px;
  background: rgba(31, 41, 51, 0.62);
  backdrop-filter: blur(8px);
}

.search-dialog {
  width: min(680px, 100%);
  max-height: calc(100vh - 120px);
  margin: 0 auto;
  overflow: hidden;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
}

.search-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 17px;
}

.search-box button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
}

.search-results {
  max-height: calc(100vh - 190px);
  overflow: auto;
  padding: 8px 16px 16px;
}

.search-result {
  display: block;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.search-result strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 22px;
  line-height: 1.35;
}

.search-result span {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
}

.search-empty {
  margin: 22px 0;
  color: var(--muted);
  text-align: center;
}

/* Tag chips */
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 30px;
}

.tag-chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.7;
  transition: background 0.15s, color 0.15s;
}

.tag-chip:hover {
  background: var(--accent);
  color: #fff;
}

/* Tags page */
.tags-page-header {
  margin-bottom: 32px;
}

.tags-page-header h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 700;
}

.tags-page-header p {
  margin: 0;
  color: var(--muted);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 36px;
}

.tag-cloud-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.tag-cloud-item:hover,
.tag-cloud-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.tag-cloud-item em {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

.tag-group {
  scroll-margin-top: 22px;
}

.tag-group[hidden] {
  display: none;
}

.tag-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.tag-group-header h2 {
  margin: 0;
  color: var(--strong);
  font-size: 22px;
}

@media (max-width: 640px) {
  .header-menu {
    position: relative;
    padding: 0 15px;
    height: auto;
    min-height: 58px;
  }

  .header-item-container {
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .header-item-title a.title {
    font-size: 22px;
  }

  .header-item a {
    font-size: 15px;
  }

  .entry-header {
    display: none;
  }

  body#home .entry-header,
  body#post-index .entry-header,
  body#post .entry-header.has-image,
  body#page .entry-header.has-image {
    display: grid;
    height: 260px;
  }

  body#home .entry-header .header-title,
  body#post-index .entry-header .header-title,
  .entry-header.has-image .header-title {
    display: none;
  }

  #main {
    margin-top: 42px;
  }

  body#post #main,
  body#page #main {
    width: auto;
    margin: 0;
  }

  #post .entry-content,
  #page .entry-content {
    border-radius: 0;
    margin-bottom: 15px;
    padding: 10px 15px;
  }

  .has-post-toc .post-toc {
    display: block;
    max-height: 220px;
    overflow-y: auto;
    margin: 0 15px 28px;
    padding: 14px 0 16px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .has-post-toc .post-toc-inner {
    position: static;
  }

  .entry-title {
    font-size: 25px;
  }

  .post-title {
    font-size: 26px;
  }

  .archive-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .archive-group-header {
    display: block;
  }

  .archive-group-header > span {
    display: inline-block;
    margin-top: 8px;
  }

  .tag-cloud {
    gap: 6px;
  }

  .tag-cloud-item {
    font-size: 13px;
  }
}
