/* ── Design tokens ── */
:root {
  --accent-1: #12a892;
  --accent-2: #1e7fc0;
  --accent-grad: linear-gradient(135deg, #12a892, #1e7fc0);
  --ink: #1a1a1a;
  --paper: #ffffff;
  --paper-alt: #f7f9f9;
  --muted: #5c6b6a;
  --border: #e0e6e5;
  --max-width: 760px;
  --header-height: 60px;
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    Arial,
    sans-serif;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1;
}

a {
  color: var(--accent-1);
  text-decoration: none;
}
a:hover {
  color: var(--accent-2);
  text-decoration: underline;
}
img {
  max-width: 100%;
}

/* ── Container ── */
.container {
  max-width: calc(var(--max-width) + 2rem);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Site header ── */
.site-header {
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border);
}

.site-header::after {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(135deg, #12a892, #1e7fc0);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--header-height);
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}

.site-brand:hover {
  color: var(--accent-1);
  text-decoration: none;
}
.site-brand img {
  width: 32px;
  height: 32px;
}

/* ── Navigation ── */
.site-nav {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  margin-left: auto;
}

.nav-link {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  transition:
    color 0.15s,
    background-color 0.15s;
}

.nav-link:hover {
  color: var(--accent-1);
  background: #f0faf8;
  text-decoration: none;
}
.nav-link.active {
  color: var(--accent-1);
  font-weight: 600;
}

/* ── Language switcher ── */
.lang-switcher {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-shrink: 0;
}

.lang-switcher a,
.lang-switcher .lang-active {
  font-size: 1.15rem;
  line-height: 1;
  text-decoration: none;
  padding: 0.1rem 0.15rem;
  border-radius: 3px;
  transition: opacity 0.15s;
  display: inline-flex;
}

.lang-switcher a {
  opacity: 0.4;
}
.lang-switcher a:hover {
  opacity: 0.75;
  text-decoration: none;
}
.lang-switcher .lang-active {
  opacity: 1;
}

/* ── Site footer ── */
.site-footer {
  background: var(--paper-alt);
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  text-align: center;
}

.footer-inner a {
  color: var(--muted);
}
.footer-inner a:hover {
  color: var(--accent-1);
}
.footer-sep {
  opacity: 0.4;
}

/* ── Article (single page) ── */
.article-wrap {
  padding-top: 2.5rem;
  padding-bottom: 4rem;
}

.article-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.article-title {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  margin: 0 0 0.5rem;
}

.article-meta {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0;
}

/* ── Table of contents ── */
.toc {
  background: var(--paper-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin: 0 0 2rem;
  font-size: 0.9rem;
}

.toc summary {
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

.toc summary::-webkit-details-marker {
  display: none;
}

.toc summary::before {
  content: '▸';
  font-size: 0.7em;
  color: var(--accent-1);
  transition: transform 0.15s;
  display: inline-block;
}

.toc[open] summary::before {
  transform: rotate(90deg);
}

.toc nav {
  margin-top: 0.6rem;
}

.toc ul {
  margin: 0;
  padding-left: 1rem;
  list-style: none;
}

.toc ul ul {
  padding-left: 1rem;
  margin-top: 0.1rem;
}
.toc li {
  margin: 0.2rem 0;
}
.toc a {
  color: var(--muted);
}
.toc a:hover {
  color: var(--accent-1);
}

/* ── ToC sidebar (hidden on mobile, shown on wide screens) ── */
.toc-sidebar {
  display: none;
}

.toc-sidebar-title {
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.1rem;
}

/* ── Article body ── */
.article-body h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 2.25rem 0 0.75rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.article-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.75rem 0 0.5rem;
}

.article-body h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.25rem 0 0.35rem;
}

.article-body p {
  margin: 0 0 1rem;
}

.article-body ul,
.article-body ol {
  margin: 0 0 1rem 0;
  padding-left: 1.4rem;
}

.article-body li + li {
  margin-top: 0.2rem;
}

.article-body code {
  background: #eef2f2;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.875em;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  overflow-wrap: break-word;
}

.article-body pre {
  background: #eef2f2;
  padding: 1rem 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

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

.article-body blockquote {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  border-left: 4px solid var(--accent-1);
  background: var(--paper-alt);
  color: var(--muted);
}

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

.article-body table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

.article-body th,
.article-body td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  overflow-wrap: break-word;
}

.article-body th {
  background: var(--paper-alt);
  font-weight: 600;
}
.article-body tr:nth-child(even) td {
  background: #fbfcfc;
}

.article-body img {
  border: 1px solid var(--ink);
  border-radius: 4px;
  display: block;
  margin: 1rem auto;
}

.article-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ── List page ── */
.list-wrap {
  padding-top: 2.5rem;
  padding-bottom: 4rem;
}

.list-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.list-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.4rem;
}
.list-description {
  color: var(--muted);
  margin: 0;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.post-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.post-card:hover {
  border-color: var(--accent-1);
  box-shadow: 0 2px 10px rgba(18, 168, 146, 0.08);
}

.post-card-title a::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.post-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
}

.post-card-title a {
  color: var(--ink);
}
.post-card-title a:hover {
  color: var(--accent-1);
  text-decoration: none;
}

.post-card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

.post-card-summary {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.post-card-chapters {
  margin: 0 0 0.75rem;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.post-card-chapters li {
  position: relative;
  padding-left: 0.7rem;
}
.post-card-chapters li::before {
  content: '·';
  position: absolute;
  left: 0;
}

.read-more {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent-1);
}
.read-more:hover {
  color: var(--accent-2);
  text-decoration: none;
}
.read-more::after {
  content: ' →';
}

/* ── Mermaid diagrams ── */
.mermaid {
  overflow-x: auto;
  text-align: center;
  margin: 1.5rem 0;
  background: var(--paper-alt);
  border-radius: 6px;
  padding: 1.25rem;
}

/* ── Hero ── */
.hero {
  background: linear-gradient(135deg, rgba(18, 168, 146, 0.07) 0%, rgba(30, 127, 192, 0.1) 100%);
  padding: 5rem 1.25rem;
  text-align: center;
}

.hero-inner {
  max-width: 640px;
  margin: 0 auto;
}

.hero-logo {
  width: 96px;
  height: 96px;
  margin-bottom: 1.25rem;
  filter: drop-shadow(0 4px 12px rgba(18, 168, 146, 0.25));
}

.hero-title {
  font-size: 3rem;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 0.75rem;
  line-height: 1.1;
}

.hero-tagline {
  font-size: 1.15rem;
  color: var(--muted);
  margin: 0 0 2.5rem;
  line-height: 1.55;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.75rem;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition:
    opacity 0.15s,
    box-shadow 0.15s;
}

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

.btn-primary {
  background: linear-gradient(135deg, #12a892, #1e7fc0);
  color: #fff;
  box-shadow: 0 2px 8px rgba(18, 168, 146, 0.3);
}

.btn-primary:hover {
  opacity: 0.9;
  color: #fff;
  box-shadow: 0 4px 16px rgba(18, 168, 146, 0.35);
}

.btn-secondary {
  background: transparent;
  color: var(--accent-1);
  border: 2px solid var(--accent-1);
}

.btn-secondary:hover {
  background: rgba(18, 168, 146, 0.06);
  color: var(--accent-1);
}

.btn-disabled {
  background: #d0d9d8;
  color: #8a9e9c;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-disabled:hover {
  opacity: 1;
  color: #8a9e9c;
}

/* ── Features ── */
.features {
  padding: 4rem 1.25rem;
  background: var(--paper);
  border-top: 1px solid var(--border);
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem;
  max-width: var(--max-width);
  margin: 0 auto;
}

.feature-card {
  text-align: center;
  padding: 1.75rem 1.25rem;
}

.feature-icon {
  font-size: 2.25rem;
  line-height: 1;
  margin-bottom: 1rem;
}

.feature-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--ink);
}

.feature-desc {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.6;
}

/* ── Responsive ── */
@media (min-width: 900px) {
  /* Four-column features grid */
  .features .container {
    max-width: 960px;
  }
  .features-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: none;
  }

  /* Two-column article layout: content + sticky ToC sidebar */
  .container.article-wrap {
    max-width: calc(var(--max-width) + 240px + 2rem + 2.5rem);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 2rem;
    align-items: start;
  }
  .article-wrap > article {
    min-width: 0;
  }
  .toc-inline {
    display: none;
  }
  .toc-sidebar {
    display: block;
    position: sticky;
    top: calc(var(--header-height) + 1.5rem);
    max-height: calc(100vh - var(--header-height) - 3rem);
    overflow-y: auto;
  }
}

@media (max-width: 600px) {
  html {
    font-size: 16px;
  }
  .header-inner {
    height: auto;
    flex-wrap: wrap;
    padding: 0.6rem 0;
    row-gap: 0.4rem;
  }
  .site-nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    justify-content: center;
    flex-wrap: wrap;
  }
  .site-nav .nav-link {
    padding: 0.25rem 0.4rem;
  }
  .article-title {
    font-size: 1.5rem;
  }
  .hero {
    padding: 3.5rem 1.25rem;
  }
  .hero-title {
    font-size: 2.25rem;
  }
  .hero-logo {
    width: 72px;
    height: 72px;
  }
}
