:root {
  color-scheme: light;
  --navy: #1d2b53;
  --navy-deep: #111a34;
  --blue: #29adff;
  --pink: #ff77a8;
  --orange: #ffa300;
  --cream: #fff1e8;
  --page: #f5f3ef;
  --paper: #fffdfa;
  --ink: #20243a;
  --muted: #6d7184;
  --line: #dedbd4;
  --soft: #eeece7;
  --code: #151b32;
  --code-ink: #f7f3ef;
  --shadow: 0 18px 52px rgb(29 43 83 / 10%);
  --sidebar-width: 320px;
  --content-width: 840px;
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  scroll-behavior: smooth;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101527;
  --paper: #171e34;
  --ink: #f4f0e9;
  --muted: #aeb5ca;
  --line: #303952;
  --soft: #202941;
  --code: #0b1020;
  --code-ink: #fff6ec;
  --shadow: 0 18px 52px rgb(0 0 0 / 28%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 32px;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.85;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: #087eb9;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

:root[data-theme="dark"] a {
  color: #63c4ff;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  height: 4px;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--orange));
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  background: var(--navy);
  color: var(--cream);
  box-shadow: 12px 0 40px rgb(10 18 40 / 12%);
}

.brand {
  padding: 32px 26px 23px;
  border-bottom: 1px solid rgb(255 241 232 / 13%);
}

.brand a {
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--pink);
  border-radius: 12px;
  background: var(--navy-deep);
  color: var(--cream);
  font: 800 16px/1 ui-monospace, monospace;
  box-shadow: 4px 4px 0 var(--pink);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  letter-spacing: 0.03em;
}

.brand small {
  margin-top: 2px;
  color: rgb(255 241 232 / 65%);
  font-size: 13px;
}

.table-of-contents {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 28px;
  scrollbar-color: rgb(255 255 255 / 20%) transparent;
  scrollbar-width: thin;
}

.table-of-contents ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-chapter {
  margin: 2px 0;
}

.toc-chapter-link {
  display: grid;
  min-height: 46px;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 9px;
  color: rgb(255 241 232 / 78%);
  font-size: 14px;
  line-height: 1.45;
  text-decoration: none;
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}

.toc-chapter-link > span {
  color: var(--pink);
  font: 700 12px/1 ui-monospace, monospace;
  letter-spacing: 0.06em;
}

.toc-chapter-link:hover,
.toc-chapter.current > .toc-chapter-link {
  background: rgb(255 255 255 / 9%);
  color: #fff;
}

.toc-chapter-link:hover {
  transform: translateX(2px);
}

.subtoc {
  display: none;
  margin: 2px 0 8px 44px !important;
  padding-left: 12px !important;
  border-left: 1px solid rgb(255 241 232 / 16%);
}

.toc-chapter.current .subtoc {
  display: block;
}

.subtoc a {
  display: block;
  padding: 5px 6px;
  color: rgb(255 241 232 / 55%);
  font-size: 12px;
  line-height: 1.45;
  text-decoration: none;
}

.subtoc a:hover,
.subtoc a.active {
  color: var(--blue);
}

.sidebar-footer {
  padding: 15px 24px 20px;
  border-top: 1px solid rgb(255 241 232 / 13%);
}

.theme-switch {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
}

.theme-switch > span:first-child {
  color: var(--orange);
  font-size: 21px;
}

.sidebar-footer p {
  margin: 2px 0 0;
  color: rgb(255 241 232 / 43%);
  font-size: 12px;
}

.mobile-header,
.drawer-overlay {
  display: none;
}

.drawer-overlay[hidden] {
  display: none !important;
}

.main-content {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 64px clamp(34px, 6vw, 96px) 24px;
}

.reader {
  width: min(100%, var(--content-width));
  margin: 0 auto;
  padding: clamp(42px, 7vw, 76px) clamp(34px, 7vw, 82px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.chapter + .chapter {
  margin-top: 110px;
  padding-top: 20px;
  border-top: 4px solid var(--soft);
}

h1,
h2,
h3 {
  position: relative;
  color: var(--ink);
  line-height: 1.32;
  text-wrap: balance;
  scroll-margin-top: 30px;
}

h1 {
  margin: 0 0 30px;
  font-size: clamp(32px, 4.5vw, 48px);
  letter-spacing: -0.035em;
}

h1::after {
  display: block;
  width: 68px;
  height: 5px;
  margin-top: 22px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink) 0 48%, var(--orange) 48% 100%);
  content: "";
}

h2 {
  margin: 70px 0 22px;
  font-size: clamp(25px, 3vw, 31px);
  letter-spacing: -0.02em;
}

h3 {
  margin: 46px 0 16px;
  font-size: 21px;
}

.heading-anchor {
  margin-left: 0.35em;
  color: var(--pink);
  font-size: 0.65em;
  opacity: 0;
  text-decoration: none;
  transition: opacity 120ms ease;
}

h1:hover .heading-anchor,
h2:hover .heading-anchor,
h3:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

p {
  margin: 0 0 1.25em;
}

strong {
  color: var(--ink);
  font-weight: 750;
}

hr {
  height: 1px;
  margin: 56px 0;
  border: 0;
  background: var(--line);
}

ul,
ol {
  margin: 0 0 1.45em;
  padding-left: 1.55em;
}

li {
  padding-left: 0.28em;
  margin: 0.42em 0;
}

li::marker {
  color: #d34879;
  font-weight: 700;
}

:root[data-theme="dark"] li::marker {
  color: var(--pink);
}

p code,
li code,
td code {
  padding: 0.14em 0.38em;
  border: 1px solid color-mix(in srgb, var(--pink), transparent 66%);
  border-radius: 5px;
  background: color-mix(in srgb, var(--pink), transparent 91%);
  color: #b32d61;
  font: 0.88em/1.4 ui-monospace, "Cascadia Code", Consolas, monospace;
  overflow-wrap: anywhere;
}

:root[data-theme="dark"] p code,
:root[data-theme="dark"] li code,
:root[data-theme="dark"] td code {
  color: #ff9fc2;
}

.code-block {
  position: relative;
  margin: 28px 0 32px;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 7%);
  border-radius: 13px;
  background: var(--code);
  box-shadow: 0 12px 26px rgb(12 17 34 / 13%);
}

.code-toolbar {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 18px;
  border-bottom: 1px solid rgb(255 255 255 / 8%);
  color: #9ea9c9;
  font: 700 12px/1 ui-monospace, "Cascadia Code", Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.copy-button {
  min-width: 54px;
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: rgb(255 255 255 / 7%);
  color: #dce3fa;
  cursor: pointer;
  font: 13px/1 inherit;
}

.copy-button:hover {
  background: rgb(255 255 255 / 13%);
}

pre {
  margin: 0;
  overflow-x: auto;
  padding: 22px;
  overscroll-behavior-x: contain;
  scrollbar-color: rgb(255 255 255 / 22%) transparent;
}

pre code {
  display: block;
  min-width: max-content;
  color: var(--code-ink);
  font: 15px/1.65 ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  tab-size: 2;
}

.language-text {
  color: #82d8c5;
}

.table-wrap {
  max-width: 100%;
  margin: 26px 0 34px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  overscroll-behavior-x: contain;
}

table {
  width: 100%;
  min-width: 540px;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.6;
}

th,
td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  background: var(--soft);
  color: var(--ink);
  font-weight: 750;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--soft), transparent 52%);
}

blockquote {
  margin: 28px 0;
  padding: 18px 22px;
  border-left: 5px solid var(--blue);
  border-radius: 0 8px 8px 0;
  background: var(--soft);
  color: var(--muted);
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 78px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.chapter-nav a {
  display: flex;
  min-height: 86px;
  flex-direction: column;
  justify-content: center;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  text-decoration: none;
  transition: border-color 150ms ease, transform 150ms ease;
}

.chapter-nav a:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
}

.chapter-nav a span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.chapter-nav .next {
  text-align: right;
}

.page-footer {
  display: flex;
  width: min(100%, var(--content-width));
  justify-content: space-between;
  gap: 18px;
  margin: 28px auto 0;
  color: var(--muted);
  font-size: 13px;
}

.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--pink);
  color: var(--navy-deep);
  cursor: pointer;
  font-size: 22px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 8px 24px rgb(17 26 52 / 22%);
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@media (max-width: 980px) {
  html {
    scroll-padding-top: 76px;
  }

  body.menu-open {
    overflow: hidden;
  }

  .mobile-header {
    position: fixed;
    inset: 0 0 auto;
    z-index: 70;
    display: grid;
    min-height: 64px;
    grid-template-columns: 48px 1fr 48px;
    align-items: center;
    gap: 6px;
    padding: max(4px, env(safe-area-inset-top)) 10px 4px;
    border-bottom: 1px solid rgb(255 255 255 / 10%);
    background: color-mix(in srgb, var(--navy), transparent 4%);
    color: var(--cream);
    backdrop-filter: blur(15px);
  }

  .mobile-title {
    overflow: hidden;
    color: inherit;
    font-size: 15px;
    font-weight: 750;
    text-align: center;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .icon-button {
    display: grid;
    width: 44px;
    height: 44px;
    place-content: center;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: inherit;
    cursor: pointer;
  }

  .menu-button span {
    display: block;
    width: 21px;
    height: 2px;
    margin: 2px;
    border-radius: 2px;
    background: currentColor;
  }

  .theme-button span {
    color: var(--orange);
    font-size: 23px;
  }

  .sidebar {
    top: 64px;
    width: min(88vw, 340px);
    transform: translateX(-104%);
    transition: transform 210ms ease;
    box-shadow: 16px 0 48px rgb(0 0 0 / 32%);
  }

  .sidebar .brand {
    padding-top: 22px;
    padding-bottom: 18px;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: block;
    border: 0;
    background: rgb(7 10 22 / 58%);
    backdrop-filter: blur(2px);
  }

  .main-content {
    margin-left: 0;
    padding: 92px clamp(18px, 5vw, 44px) 24px;
  }

  .reader {
    padding: clamp(34px, 7vw, 58px) clamp(22px, 6vw, 56px);
  }
}

@media (max-width: 600px) {
  body {
    font-size: 17px;
    line-height: 1.82;
  }

  .main-content {
    padding: 76px 0 0;
  }

  .reader {
    width: 100%;
    padding: 38px 20px 52px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chapter + .chapter {
    margin-top: 82px;
    padding-top: 36px;
  }

  h1 {
    margin-bottom: 25px;
    font-size: 31px;
  }

  h2 {
    margin-top: 58px;
    font-size: 25px;
  }

  h3 {
    font-size: 20px;
  }

  .heading-anchor {
    display: none;
  }

  pre {
    padding: 18px;
  }

  pre code {
    font-size: 14px;
  }

  .code-block {
    margin-right: -5px;
    margin-left: -5px;
    border-radius: 10px;
  }

  .table-wrap {
    width: calc(100% + 20px);
    margin-right: -10px;
    margin-left: -10px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .chapter-nav {
    grid-template-columns: 1fr;
  }

  .chapter-nav > span:empty {
    display: none;
  }

  .page-footer {
    margin: 0;
    padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
    background: var(--navy);
    color: rgb(255 241 232 / 62%);
  }

  .back-to-top {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
}

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

@media print {
  .sidebar,
  .mobile-header,
  .reading-progress,
  .back-to-top,
  .copy-button,
  .chapter-nav,
  .page-footer,
  .heading-anchor {
    display: none !important;
  }

  body,
  .reader {
    background: #fff;
    color: #000;
  }

  .main-content {
    margin: 0;
    padding: 0;
  }

  .reader {
    width: 100%;
    max-width: none;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .chapter {
    break-before: page;
  }

  .chapter:first-child {
    break-before: auto;
  }
}
