:root,
[data-theme="light"] {
  --background-color: #fff;
  --text-color: #000;
  --text-color-secondary: #666;
  --link-color: #016afb;
  --border-color: #e2e2e2;
  --card-background: #fff;
  --card-hover-background: #f5f7fa;
  --header-background: #3F9FFF;
  --header-text: #fff;
  --header-text-hover: rgba(255, 255, 255, 0.85);
  --header-border: rgba(255, 255, 255, 0.3);
  --hero-background: #1a1a2e;
  --hero-text: #fff;
  --search-background: #fff;
  --mark-background: #fff3cd;
  --footer-background: #1a1a2e;
  --logo-light-display: none;
  --logo-dark-display: block;
}

[data-theme="dark"] {
  --background-color: #0a0a0a;
  --text-color: #ccc;
  --text-color-secondary: #999;
  --link-color: #03a0ff;
  --border-color: #2a2a2a;
  --card-background: #151515;
  --card-hover-background: #1a1a1a;
  --header-background: #111;
  --header-text: #ccc;
  --header-text-hover: #fff;
  --header-border: #2a2a2a;
  --hero-background: #111;
  --hero-text: #eee;
  --search-background: #1a1a1a;
  --mark-background: #5a4800;
  --footer-background: #111;
  --logo-light-display: none;
  --logo-dark-display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background-color: #0a0a0a;
    --text-color: #ccc;
    --text-color-secondary: #999;
    --link-color: #03a0ff;
    --border-color: #2a2a2a;
    --card-background: #151515;
    --card-hover-background: #1a1a1a;
    --header-background: #111;
    --header-text: #ccc;
    --header-text-hover: #fff;
    --header-border: #2a2a2a;
    --hero-background: #111;
    --hero-text: #eee;
    --search-background: #1a1a1a;
    --mark-background: #5a4800;
    --footer-background: #111;
    --logo-light-display: none;
    --logo-dark-display: block;
  }
}

* {
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
  box-sizing: border-box;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--background-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-synthesis: none;
  font-weight: normal;
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  text-decoration: none;
  color: var(--link-color);
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

/* Header */
.header {
  background: var(--header-background);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--header-text);
}

.logo:hover {
  text-decoration: none;
}

.logo picture {
  display: flex;
  align-items: center;
}

.logo-light {
  display: none;
}

.logo-dark {
  display: block;
}

.header-title {
  font-size: 14px;
  font-weight: 600;
  padding-left: 12px;
  border-left: 1px solid var(--header-border);
  color: var(--header-text);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--header-text);
}

.nav-link:hover {
  color: var(--header-text-hover);
  text-decoration: none;
}

.header-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--search-background);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 12px;
}

.header-search svg {
  flex-shrink: 0;
  color: var(--text-color-secondary);
}

.header-search input {
  background: none;
  color: var(--text-color);
  font-size: 14px;
  font-family: inherit;
  width: 180px;
}

.header-search input::placeholder {
  color: var(--text-color-secondary);
}

/* Hero */
.hero {
  background: var(--header-background);
  color: var(--header-text);
  padding: 16px 24px 28px;
  text-align: center;
}

.hero h1 {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 24px;
}

.hero--compact {
  padding: 12px 24px 28px;
}

/* Search */
.search-form {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  display: flex;
}

.search-form input {
  width: 100%;
  padding: 14px 48px 14px 20px;
  font-size: 16px;
  border-radius: 24px;
  background: var(--search-background);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  font-family: inherit;
}

.search-form input:focus {
  border-color: var(--link-color);
  box-shadow: 0 0 0 3px rgba(1, 106, 251, 0.15);
}

.search-form input::placeholder {
  color: var(--text-color-secondary);
}

.search-form button {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  cursor: pointer;
  color: var(--text-color-secondary);
  padding: 4px;
}

.search-form button:hover {
  color: var(--text-color);
}

/* Container */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
  flex: 1;
}

/* Main */
.main {
  flex: 1;
}

/* Collections Grid */
.collections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.collection-card {
  display: block;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 28px 24px;
  color: var(--text-color);
  transition: background-color 0.15s, border-color 0.15s;
}

.collection-card:hover {
  background: var(--card-hover-background);
  border-color: var(--link-color);
  text-decoration: none;
}

.collection-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 12px;
  color: var(--link-color);
}

.collection-icon svg {
  width: 100%;
  height: 100%;
}

.collection-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.collection-card p {
  font-size: 14px;
  color: var(--text-color-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.collection-card--small h2 {
  font-size: 16px;
}

.article-count {
  font-size: 13px;
  color: var(--text-color-secondary);
}

/* Sub-collections */
.sub-collections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

/* Collection Page */
.collection-page h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
}

.collection-description {
  color: var(--text-color-secondary);
  margin-bottom: 32px;
  font-size: 16px;
}

/* Articles List */
.articles-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.article-card {
  display: block;
  padding: 18px 20px;
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 8px;
  color: var(--text-color);
  transition: background-color 0.15s, border-color 0.15s;
}

.article-card:hover {
  background: var(--card-hover-background);
  border-color: var(--link-color);
  text-decoration: none;
}

.article-card h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.article-card p {
  font-size: 14px;
  color: var(--text-color-secondary);
  line-height: 1.5;
}

.article-collection {
  font-size: 12px;
  color: var(--text-color-secondary);
  margin-top: 6px;
  display: inline-block;
}

/* Breadcrumb */
.breadcrumb {
  margin-bottom: 24px;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.breadcrumb li {
  font-size: 14px;
  color: var(--text-color-secondary);
}

.breadcrumb li:not(:last-child)::after {
  content: "/";
  margin-left: 8px;
  color: var(--border-color);
}

.breadcrumb li a {
  color: var(--text-color-secondary);
}

.breadcrumb li a:hover {
  color: var(--text-color);
  text-decoration: none;
}

.breadcrumb li[aria-current="page"] {
  color: var(--text-color);
}

/* Article Layout */
.article-layout {
  display: flex;
  gap: 48px;
  max-width: 960px;
  margin: 0 auto;
}

/* Article Page */
.article-page {
  max-width: 660px;
  min-width: 0;
  margin: 0 auto;
}

.article-page h1 {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.5px;
  margin-bottom: 0;
}

.article-date {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-color-secondary);
  margin-top: 8px;
  margin-bottom: 0;
}

.article-meta {
  display: flex;
  align-items: center;
  margin-top: 12px;
  margin-bottom: 32px;
}

.article-meta .author-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 10px;
  flex-shrink: 0;
}

.article-meta-text {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-color-secondary);
}

.article-body {
  font-size: 16.5px;
  line-height: 1.7;
  color: var(--text-color);
}

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4,
.article-body h5,
.article-body h6 {
  margin-top: 48px;
  margin-bottom: 16px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.3px;
  scroll-margin-top: 80px;
}

.article-body h2 {
  font-size: 22px;
}

.article-body h3 {
  font-size: 18px;
}

.article-body h4 {
  font-size: 16.5px;
  font-weight: 600;
}

.article-body p {
  margin-bottom: 24px;
}

.article-body p.no-margin {
  margin-bottom: 0;
}

.article-body ul,
.article-body ol {
  margin-bottom: 24px;
  padding-left: 20px;
}

.article-body li {
  margin-bottom: 10px;
  list-style: disc;
  line-height: 1.7;
  padding-left: 4px;
}

.article-body ol li {
  list-style: decimal;
}

.article-body img {
  border-radius: 4px;
  display: block;
  margin: 8px 0;
}

.article-body a {
  color: var(--link-color);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--link-color) 40%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}

.article-body a:hover {
  text-decoration-color: var(--link-color);
}

.article-body blockquote {
  border-left: 2px solid var(--border-color);
  padding: 0 0 0 20px;
  margin: 28px 0;
  color: var(--text-color-secondary);
}

.article-body code {
  background: var(--card-hover-background);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 14px;
}

.article-body pre {
  background: var(--card-hover-background);
  padding: 20px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 28px 0;
  font-size: 13.5px;
  line-height: 1.65;
}

.article-body pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 28px 0;
  font-size: 15px;
}

.article-body th,
.article-body td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  line-height: 1.6;
}

.article-body th {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-color-secondary);
}

/* Related Articles */
.related-articles {
  margin-top: 48px;
}

.related-articles hr {
  border-top: 1px solid var(--border-color);
  margin: 0 0 32px;
}

.related-articles-heading {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-color-secondary);
  margin-bottom: 12px;
}

.related-articles-card {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-background);
  padding: 8px 12px;
}

.related-article {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-color);
  font-size: 15px;
  transition: background-color 0.15s, color 0.15s;
}

.related-article:hover {
  background: var(--card-hover-background);
  color: var(--link-color);
  text-decoration: none;
}

.related-article svg {
  flex-shrink: 0;
  color: var(--link-color);
  opacity: 0;
  transition: opacity 0.15s;
}

.related-article:hover svg {
  opacity: 1;
}

/* Table of Contents */
.toc {
  flex: 0 0 200px;
  position: sticky;
  top: 80px;
  align-self: flex-start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-top: 64px;
}

.toc-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-color-secondary);
  margin-bottom: 12px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 2px solid var(--border-color);
}

.toc-list li {
  margin: 0;
}

.toc-list a {
  display: block;
  padding: 4px 0 4px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-color-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.toc-list a:hover {
  color: var(--text-color);
  text-decoration: none;
}

.toc-list a.active {
  color: var(--link-color);
  border-left-color: var(--link-color);
}

.toc-list a[data-level="2"] {
  padding-left: 24px;
}

/* Search Results */
.search-results h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 20px;
}

.no-results {
  color: var(--text-color-secondary);
  font-size: 16px;
}

mark {
  background: var(--mark-background);
  color: var(--text-color);
  padding: 1px 2px;
  border-radius: 2px;
}

/* 404 */
.not-found {
  text-align: center;
  padding: 80px 0;
}

.not-found h1 {
  font-size: 28px;
  margin-bottom: 12px;
}

.not-found p {
  color: var(--text-color-secondary);
  margin-bottom: 24px;
}

.btn {
  display: inline-block;
  padding: 10px 24px;
  background: var(--header-background);
  color: #fff;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s;
}

.btn:hover {
  text-decoration: none;
  color: #fff;
  opacity: 0.85;
}

/* Footer */
.footer {
  display: block;
  padding: 0;
  line-height: 2;
  margin-top: auto;
  margin-bottom: 48px;
}

.footer ul {
  padding: 0;
  margin: 0;
}

.footer ul li {
  list-style: none;
}

.footer-inner {
  position: relative;
  max-width: 980px;
  margin: 0 auto;
  padding: 96px 0 0;
}

.footer-columns {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  width: 100%;
}

.footer-list {
  flex-basis: 20%;
  margin-bottom: 40px;
}

.footer-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
  display: inline-block;
  color: var(--text-color);
}

.footer-section {
  margin: 0;
}

.footer-section li {
  width: 100%;
}

.footer-section a {
  color: var(--text-color-secondary);
  font-size: 14px;
  font-weight: 400;
}

.footer-section a:hover {
  color: var(--text-color);
  text-decoration: none;
}

.footer-copyright {
  text-align: center;
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-color);
}

/* Responsive */
@media (max-width: 1024px) {
  .article-layout {
    display: block;
  }

  .toc {
    display: none;
  }

  .footer-inner {
    max-width: 692px;
  }
}

@media (max-width: 767px) {
  .footer-inner {
    width: 100%;
    max-width: none;
  }

  .hero {
    padding: 40px 16px;
  }

  .hero h1 {
    font-size: 24px;
  }

  .search-form input {
    padding: 10px 40px 10px 16px;
    font-size: 14px;
  }

  .container {
    padding: 24px 16px;
  }

  .collections-grid {
    grid-template-columns: 1fr;
  }

  .sub-collections {
    grid-template-columns: 1fr;
  }

  .footer-list {
    position: relative;
    flex-basis: 100%;
    margin: 0;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
  }

  .footer-title {
    padding: 10px 0;
    cursor: pointer;
    display: block;
    margin: 0;
  }

  .footer-title::after {
    content: "+";
    float: right;
    font-size: 14px;
    font-weight: 400;
    margin-top: -2px;
    margin-right: 8px;
    transition: transform 0.3s ease;
  }

  .footer-title.active::after {
    transform: rotate(45deg) scale(1.08);
  }

  .footer-list .footer-section {
    overflow: hidden;
    margin-bottom: 0;
    max-height: 0;
    transition: max-height 0.3s ease-out;
  }

  .footer-list.active .footer-section {
    max-height: 600px;
  }

  .footer-section li {
    margin-bottom: 15px;
  }

  .header-inner {
    padding: 0 16px;
  }

  .header-title {
    display: none;
  }

  .header-nav {
    gap: 10px;
    flex: 1;
    justify-content: flex-end;
  }

  .header-search {
    padding: 6px 8px;
    flex: 1;
    margin-left: 10px;
  }

  .header-search input {
    width: 100%;
    font-size: 13px;
  }

  .header-search + .nav-link {
    display: none;
  }
}
