:root {
  --reader-nav-height: 74px;
  --reader-accent: #0078d4;
  --reader-text: #e5edf8;
  --reader-muted: #b4c1d3;
  --reader-surface: rgba(20, 28, 42, 0.88);
  --reader-border: rgba(148, 163, 184, 0.25);
}

html {
  overflow-x: clip;
  scroll-padding-top: 0;
}

body {
  overflow-x: clip;
}

body.light {
  --reader-text: #243247;
  --reader-muted: #64748b;
  --reader-surface: rgba(255, 255, 255, 0.9);
  --reader-border: rgba(100, 116, 139, 0.22);
}

nav.reader-nav {
  gap: 12px;
  color: var(--reader-text);
}

.reader-back-top:focus-visible,
.reader-toc a:focus-visible,
.reader-toc-mobile a:focus-visible {
  outline: 3px solid #60b7f5;
  outline-offset: 3px;
}

main.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 960px;
  margin: 0 auto;
  padding: calc(var(--reader-nav-height) + 28px) 24px 64px;
}

.reader-layout .article-view {
  min-width: 0;
  padding: clamp(24px, 4vw, 46px);
  color: var(--reader-text);
  background: rgba(19, 27, 39, 0.96);
}

body.light .reader-layout .article-view.glass {
  background: rgba(255, 255, 255, 0.96);
  color: var(--reader-text);
}

.reader-layout .article-view h1 {
  font-size: clamp(1.75rem, 3vw, 2.4rem);
  line-height: 1.35;
  overflow-wrap: anywhere;
  letter-spacing: -0.025em;
  margin-bottom: 20px;
}

.reader-layout .meta-bar {
  gap: 10px 20px;
  line-height: 1.7;
  margin-bottom: 30px;
  font-size: 0.88rem;
  color: var(--reader-muted);
  opacity: 1;
}

.reader-layout .meta-bar > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.reader-layout .article-body {
  color: inherit;
}

.reader-layout .article-body h2,
.reader-layout .article-body h3 {
  scroll-margin-top: calc(var(--reader-nav-height) + 24px);
  color: inherit;
}

.reader-layout .article-body img {
  height: auto;
  max-width: 100%;
}

.reader-layout .article-body pre {
  max-width: 100%;
  line-height: 1.7;
  letter-spacing: 0;
}

.reader-layout .article-body pre code,
.reader-layout .article-body pre code * {
  font-family: Consolas, "Cascadia Code", monospace;
}

.reader-layout .article-body .code-window {
  margin: 1.4em 0;
  border-radius: 12px;
  overflow: hidden;
  background: #222a39;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
}
.reader-layout .article-body .code-window-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 32px;
  padding: 0 18px;
  background: #151d2b;
  color: #aab7ca;
}
.reader-layout .article-body .code-window-language {
  font:
    600 0.75rem/1.4 "Segoe UI",
    sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.reader-layout .article-body .code-window .code-copy {
  position: static;
  margin: 0;
  padding: 5px 0 5px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #c8d3e2;
  font:
    400 0.78rem/1.4 "Segoe UI",
    "Microsoft YaHei",
    sans-serif;
  cursor: pointer;
  transition: color 0.2s;
}
.reader-layout .article-body .code-window .code-copy:hover {
  background: transparent;
  color: #fff;
}
.reader-layout .article-body .code-window .code-copy.is-copied {
  color: #68d391;
}
.reader-layout .article-body .code-window .code-copy.is-failed {
  color: #fca5a5;
}
.reader-layout .article-body .code-window .code-copy:focus-visible {
  outline: 2px solid #80c8ff;
  outline-offset: 3px;
}
.reader-layout .article-body .code-window pre {
  margin: 0;
  padding: 18px 20px;
  border: 0;
  border-radius: 0;
  background: #222a39 !important;
  color: #e2e8f0 !important;
  overflow-x: auto;
}
.reader-layout .article-body .code-window pre::before {
  display: none;
}
.reader-layout .article-body .code-window pre code {
  display: block;
  overflow: visible;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  padding: 0;
  background: transparent !important;
  color: inherit;
  font-size: 0.9rem;
  line-height: 1.7;
}
@media (max-width: 768px) {
  .reader-layout .article-body .code-window-header {
    min-height: 36px;
    padding: 0 14px;
  }
  .reader-layout .article-body .code-window pre {
    padding: 15px 14px;
  }
  .reader-layout .article-body .code-window pre code {
    font-size: 0.82rem;
  }
}

.reader-layout .article-body table {
  display: block;
  max-width: 100%;
  overflow: auto;
  border-collapse: collapse;
  margin: 1.25em 0;
}

.reader-layout .article-body th,
.reader-layout .article-body td {
  padding: 0.6em 0.85em;
  border: 1px solid var(--reader-border);
}

.reader-layout .article-body a:not(.jump-btn) {
  color: #60b7f5;
  text-underline-offset: 0.2em;
}

body.light .reader-layout .article-body a:not(.jump-btn) {
  color: #0067b8;
}

.reader-layout .article-kicker {
  color: #60b7f5;
}

body.light .reader-layout .article-kicker {
  color: #0078d4;
}

.reader-toc {
  display: none;
  position: sticky;
  top: var(--reader-toc-top, calc(var(--reader-nav-height) + 28px));
  padding: 18px 12px;
  border: 1px solid var(--reader-border);
  border-radius: 14px;
  background: var(--reader-surface);
  color: var(--reader-text);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.08);
}

.reader-toc h2 {
  margin: 0 8px 12px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.reader-toc ol,
.reader-toc-mobile ol {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: calc(100dvh - var(--reader-nav-height) - 140px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.reader-toc a,
.reader-toc-mobile a {
  display: block;
  padding: 8px 10px;
  border-left: 2px solid transparent;
  border-radius: 0 7px 7px 0;
  color: var(--reader-muted);
  font-size: 0.84rem;
  line-height: 1.6;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.reader-toc a:hover,
.reader-toc-mobile a:hover {
  background: rgba(0, 120, 212, 0.09);
  color: var(--reader-text);
}

.reader-toc a[aria-current="location"],
.reader-toc-mobile a[aria-current="location"] {
  border-left-color: #0078d4;
  background: rgba(0, 120, 212, 0.13);
  color: #60b7f5;
  font-weight: 600;
}

body.light .reader-toc a[aria-current="location"],
body.light .reader-toc-mobile a[aria-current="location"] {
  color: #0067b8;
}

.reader-toc .toc-subheading a,
.reader-toc-mobile .toc-subheading a {
  padding-left: 23px;
  font-size: 0.8rem;
}

.reader-toc-mobile {
  margin: 0 0 28px;
  padding: 12px 14px;
  border: 1px solid var(--reader-border);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.06);
  color: var(--reader-text);
}

.reader-toc-mobile summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.6;
}

.reader-toc-mobile[open] summary {
  margin-bottom: 10px;
}

.reader-progress {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--reader-nav-height);
  height: 3px;
  background: rgba(148, 163, 184, 0.12);
  z-index: 1001;
  pointer-events: none;
}

.reader-progress-fill {
  height: 100%;
  background: #0078d4;
  transform-origin: left;
  transform: scaleX(0);
}

.reader-back-top {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--reader-border);
  border-radius: 12px;
  background: var(--reader-surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--reader-text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.reader-back-top[hidden] {
  display: none;
}

@media (min-width: 1440px) {
  .has-toc .reader-toc {
    display: block;
    position: fixed;
    left: calc(50% + 480px);
    width: 220px;
  }
  .reader-toc-mobile {
    display: none;
  }
}

@media (max-width: 768px) {
  main.reader-layout {
    padding: calc(var(--reader-nav-height) + 18px) 12px 70px;
  }
  .reader-layout .article-view {
    padding: 25px 20px;
    border-radius: 14px;
  }
  .reader-layout .meta-bar {
    gap: 8px 14px;
    font-size: 0.8rem;
    margin-bottom: 24px;
  }
  .reader-nav .nav-back {
    font-size: 0.85rem;
    padding: 0.3rem 0;
  }
  .reader-controls {
    gap: 7px;
  }
  .reader-nav .theme-toggle {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }
  .reading-mode-toggle {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 0.78rem;
  }
  .reader-back-top {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding: 9px 11px;
  }
}

@media (max-width: 360px) {
  main.reader-layout {
    padding-left: 8px;
    padding-right: 8px;
  }
  .reader-layout .article-view {
    padding: 22px 16px;
  }
  .reader-nav {
    padding-left: 12px;
    padding-right: 12px;
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reader-layout *,
  .reader-progress-fill {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
