@font-face {
  font-family: "TsangerJinKai01";
  src: url("./TsangerJinKai01-W04.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --text: #1f2933;
  --muted: #52606d;
  --surface: rgba(255, 255, 255, 0.82);
  --border: rgba(15, 23, 42, 0.08);
  --accent: #2b8aeb;
  --accent-contrast: #ffffff;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  --code-bg: #f6f8fa;
  --code-border: #d0d7de;
  --blockquote-border: rgba(43, 138, 235, 0.4);
}

body[data-theme="dark"] {
  --bg: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --surface: rgba(15, 23, 42, 0.75);
  --border: rgba(148, 163, 184, 0.15);
  --accent: #60a5fa;
  --accent-contrast: #0f172a;
  --shadow: 0 16px 48px rgba(2, 6, 23, 0.48);
  --code-bg: #282c34;
  --code-border: #3b4048;
  --blockquote-border: rgba(96, 165, 250, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Quicksand", "Inter", "TsangerJinKai01", "Segoe UI", "Noto Sans SC",
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

body:lang(zh),
body:lang(zh-cn),
body:lang(zh-hans),
body:lang(zh-tw),
body:lang(zh-hant),
body:lang(zh-CN),
body:lang(zh-TW) {
  font-family: "Quicksand", "TsangerJinKai01", "Inter", "Segoe UI", "Helvetica Neue",
    Arial, sans-serif;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.layout {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.top-bar {
  backdrop-filter: blur(16px);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
}

.brand a {
  font-size: 1.25rem;
  font-weight: 600;
  color: inherit;
  text-decoration: none;
}

.controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.control {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.language-dropdown::after {
  display: none;
}

.language-dropdown__button {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  border-radius: 0.9rem;
  padding: 0.55rem 2.5rem 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.1;
  background: color-mix(in srgb, var(--surface) 96%, rgba(255, 255, 255, 0.45));
  color: inherit;
  min-width: 8rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease,
    color 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  position: relative;
}

.language-dropdown__button::after {
  content: "";
  position: absolute;
  pointer-events: none;
  right: 1.15rem;
  top: 50%;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-50%) rotate(45deg);
  opacity: 0.65;
}

.language-dropdown__button:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--surface) 100%, rgba(255, 255, 255, 0.55));
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.language-dropdown__button:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.language-dropdown__current {
  flex: 1;
  text-align: left;
}

.language-dropdown__menu {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  min-width: 100%;
  background: color-mix(in srgb, var(--surface) 100%, rgba(255, 255, 255, 0.6));
  border-radius: 0.9rem;
  border: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
  overflow: hidden;
}

.language-dropdown.is-open .language-dropdown__menu {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.language-dropdown__option {
  width: 100%;
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.language-dropdown__option:hover,
.language-dropdown__option:focus {
  outline: none;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.language-dropdown__option.is-active {
  background: color-mix(in srgb, var(--accent) 18%, rgba(255, 255, 255, 0.6));
  color: var(--accent);
  font-weight: 600;
}

.language-dropdown__option.is-active:hover,
.language-dropdown__option.is-active:focus {
  background: color-mix(in srgb, var(--accent) 25%, rgba(255, 255, 255, 0.55));
}

.language-dropdown__select {
  position: absolute;
}

body[data-theme="dark"] .language-dropdown__button {
  background: color-mix(in srgb, var(--surface) 82%, rgba(15, 23, 42, 0.55));
  border-color: color-mix(in srgb, var(--border) 55%, transparent);
}

body[data-theme="dark"] .language-dropdown__button:hover {
  background: color-mix(in srgb, var(--surface) 90%, rgba(15, 23, 42, 0.35));
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.32);
}

body[data-theme="dark"] .language-dropdown__menu {
  background: color-mix(in srgb, var(--surface) 92%, rgba(15, 23, 42, 0.55));
  border-color: color-mix(in srgb, var(--border) 75%, transparent);
}

body[data-theme="dark"] .language-dropdown__option:hover,
body[data-theme="dark"] .language-dropdown__option:focus {
  background: color-mix(in srgb, var(--accent) 22%, rgba(15, 23, 42, 0.55));
}

body[data-theme="dark"] .language-dropdown__option.is-active {
  background: color-mix(in srgb, var(--accent) 35%, rgba(15, 23, 42, 0.45));
  color: var(--accent-contrast);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  color: inherit;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

a.icon-button {
  text-decoration: none;
}

.icon-link svg {
  width: 1.2rem;
  height: 1.2rem;
}

.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.icon-button:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

.content {
  width: min(960px, 100%);
  margin: 0 auto;
  flex: 1 0 auto;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1rem, 4vw, 2rem) 4rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.hero {
  display: grid;
  gap: 1.2rem;
  justify-items: start;
}

.hero-banner {
  width: min(100%, 520px);
  display: block;
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  justify-self: center;
  height: auto;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 2.8rem);
  margin: 0;
}

.hero-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
  max-width: 60ch;
}

.hero-credit {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 60ch;
}

.hero-credit a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.hero-credit a:hover,
.hero-credit a:focus {
  text-decoration: underline;
}

.chapter-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.chapter-card {
  border-radius: 18px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 120px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.chapter-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.chapter-card strong {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
}

.section-title {
  font-size: 1.25rem;
  margin: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 2.5rem 0 1.5rem;
}

.chapters-section > .section-header:first-of-type {
  margin-top: 0;
}

.section-header .divider {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.chapter-view {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.chapter-header {
  text-align: center;
}

.chapter-header h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 3rem);
}

.chapter-body {
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  border-radius: 24px;
  padding: clamp(1.5rem, 4vw, 2.75rem);
  border: 1px solid var(--border);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
}

.chapter-body img {
  max-width: 100%;
  display: block;
  margin: 1.5rem auto;
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.18);
}

.chapter-body p {
  line-height: 1.75;
  font-size: 1.05rem;
  margin: 1rem 0;
}

.chapter-body h2,
.chapter-body h3,
.chapter-body h4 {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.chapter-body h2 {
  font-size: 1.8rem;
}

.chapter-body h3 {
  font-size: 1.4rem;
}

.chapter-body hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 2.25rem 0;
}

.chapter-body a {
  color: var(--accent);
  text-decoration: none;
}

.chapter-body a:hover {
  text-decoration: underline;
}

.chapter-body blockquote {
  border-left: 4px solid var(--blockquote-border);
  padding: 0.75rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  margin: 1.5rem 0;
  border-radius: 0 18px 18px 0;
}

.chapter-body .code-block {
  position: relative;
  margin: 1.75rem 0;
}

.chapter-body pre {
  margin: 1.75rem 0;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 16px;
  padding: 1.2rem 1.4rem;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Mono", "SFMono-Regular", Consolas,
    "Liberation Mono", "Menlo", "Courier New", "Noto Sans Mono CJK SC", "Source Han Mono SC",
    "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei", monospace, sans-serif;
  font-size: 0.95rem;
  line-height: 1.7;
}

.chapter-body .code-block pre {
  margin: 0;
  padding-right: 3.6rem;
}

.chapter-body code {
  background: color-mix(in srgb, var(--code-bg) 80%, transparent);
  border-radius: 6px;
  padding: 0.15rem 0.35rem;
  font-size: 0.92em;
  border: 1px solid color-mix(in srgb, var(--code-border) 80%, transparent);
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Mono", "SFMono-Regular", Consolas,
    "Liberation Mono", "Menlo", "Courier New", "Noto Sans Mono CJK SC", "Source Han Mono SC",
    "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei", monospace, sans-serif;
}

.chapter-body pre code {
  background: none;
  border: none;
  padding: 0;
}

.chapter-body pre code.hljs {
  display: block;
  color: inherit;
}

.chapter-body .code-copy-button {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  color: var(--muted);
  cursor: pointer;
  z-index: 1;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease,
    box-shadow 0.2s ease, transform 0.15s ease;
}

.chapter-body .code-copy-button:disabled {
  cursor: wait;
  opacity: 0.75;
}


.chapter-body .code-copy-button:hover {
  transform: translateY(-1px);
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 100%, rgba(255, 255, 255, 0.35));
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: var(--shadow);
}

.chapter-body .code-copy-button:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.chapter-body .code-copy-icon {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.chapter-body .code-copy-button.copied {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
  box-shadow: none;
}

.chapter-body .code-copy-button.error {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.35);
  color: #dc2626;
  box-shadow: none;
}

body[data-theme="dark"] .chapter-body .code-copy-button.error {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.45);
  color: #f87171;
}

body[data-theme="light"] .chapter-body pre code.hljs {
  color: #24292e;
}

body[data-theme="dark"] .chapter-body pre code.hljs {
  color: #abb2bf;
}

body[data-theme="light"] .chapter-body pre code .hljs-comment,
body[data-theme="light"] .chapter-body pre code .hljs-quote {
  color: #6a737d;
  font-style: normal;
}

body[data-theme="dark"] .chapter-body pre code .hljs-comment,
body[data-theme="dark"] .chapter-body pre code .hljs-quote {
  color: #5c6370;
  font-style: normal;
}

body[data-theme="light"] .chapter-body pre code .hljs-keyword {
  color: #d73a49;
  font-weight: 600;
}

body[data-theme="light"] .chapter-body pre code .hljs-built_in {
  color: #6f42c1;
  font-weight: 600;
}

body[data-theme="dark"] .chapter-body pre code .hljs-keyword {
  color: #c678dd;
  font-weight: 600;
}

body[data-theme="dark"] .chapter-body pre code .hljs-built_in {
  color: #61afef;
  font-weight: 600;
}

body[data-theme="light"] .chapter-body pre code .hljs-meta {
  color: #6f42c1;
  font-weight: 600;
}

body[data-theme="dark"] .chapter-body pre code .hljs-meta {
  color: #e5c07b;
  font-weight: 600;
}

body[data-theme="light"] .chapter-body pre code .hljs-number {
  color: #005cc5;
}

body[data-theme="dark"] .chapter-body pre code .hljs-number {
  color: #d19a66;
}

body[data-theme="light"] .chapter-body pre code .hljs-string {
  color: #032f62;
}

body[data-theme="dark"] .chapter-body pre code .hljs-string {
  color: #98c379;
}

.chapter-body ul,
.chapter-body ol {
  padding-left: 1.5rem;
  margin: 1rem 0;
  line-height: 1.7;
}

.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.chapter-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: inherit;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.chapter-nav .disabled {
  pointer-events: none;
  opacity: 0.45;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
}

.chapter-nav a:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  box-shadow: var(--shadow);
}

.chapter-nav .spacer {
  flex: 1;
}

.notice {
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

.notice h2 {
  margin: 0 0 0.75rem;
}

.notice p {
  margin: 0;
  line-height: 1.6;
}

.loading {
  text-align: center;
  font-size: 1.05rem;
  color: var(--muted);
  padding: 2rem 0;
}

.page-footer {
  padding: 2rem clamp(1rem, 4vw, 2.5rem);
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.page-footer a {
  color: var(--accent);
  text-decoration: none;
}

.page-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .top-bar {
    position: static;
    border-bottom: none;
    background: transparent;
    padding-bottom: 0;
  }

  .chapter-body {
    border-radius: 18px;
    padding: 1.35rem;
  }

  .chapter-nav {
    flex-direction: column;
    align-items: stretch;
  }

  .chapter-nav .spacer {
    display: none;
  }
}
