:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --ink: #141a33;
  --ink-2: #39415c;
  --muted: #69718a;
  --line: #e3e6ef;
  --accent: #2c4fc7;
  --accent-ink: #1d3596;
  --accent-soft: #eaf0ff;
  --teal: #13a89e;
  --navy: #0f1a3d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 26, 51, .04), 0 8px 24px rgba(20, 26, 51, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-head: "Manrope", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --container: 1240px;
  --sidebar: 340px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-ink); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 16px; }

.skip-link {
  position: absolute; left: 16px; top: -60px; z-index: 100;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; text-decoration: none;
}
.skip-link:focus { top: 12px; color: #fff; }

/* Top bar with language switch */
.topbar { background: var(--navy); color: #c9d2ee; font-size: 14px; }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; }
.topbar__tagline { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lang-switch { display: flex; gap: 6px; flex-shrink: 0; margin-left: auto; }
.lang-switch__btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 30px; padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .28); border-radius: 999px;
  color: #fff; font-weight: 600; font-size: 13px; letter-spacing: .04em; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.lang-switch__btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.lang-switch__btn.is-active { background: #fff; border-color: #fff; color: var(--navy); }

/* Header */
.header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header__inner { display: flex; align-items: center; gap: 24px; min-height: 72px; }
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.logo:hover { color: var(--ink); }
.logo__mark {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2c4fc7, #13a89e); color: #fff;
  font: 800 21px/1 var(--font-head);
}
.logo__text { font: 800 22px/1 var(--font-head); letter-spacing: -.01em; display: flex; flex-direction: column; gap: 3px; }
.logo__text small { font: 500 12px/1 var(--font); color: var(--muted); letter-spacing: .02em; }

.nav { margin-left: auto; min-width: 0; }
.nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.nav a {
  display: block; padding: 8px 12px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 15px; white-space: nowrap;
}
.nav a:hover { background: var(--accent-soft); color: var(--accent-ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* Layout: article + sticky sidebar on the right */
.layout { padding-top: 28px; padding-bottom: 56px; }
.main { min-width: 0; }

@media (min-width: 1024px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--sidebar);
    gap: 40px;
    align-items: start;
  }
  .sidebar {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #c5cbe0 transparent;
    padding-right: 4px;
  }
  .sidebar::-webkit-scrollbar { width: 6px; }
  .sidebar::-webkit-scrollbar-thumb { background: #c5cbe0; border-radius: 6px; }
}

/* Breadcrumbs */
.breadcrumbs ol { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 16px; padding: 0; font-size: 14px; color: var(--muted); }
.breadcrumbs li + li::before { content: "›"; margin-right: 6px; color: #a2a9bf; }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent); text-decoration: underline; }

/* Article */
.article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 40px 48px 48px;
}
.chip {
  display: inline-block; margin: 0 0 14px; padding: 4px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 13px; font-weight: 600; letter-spacing: .02em;
}
.article h1 {
  font: 800 clamp(28px, 3.4vw, 42px)/1.18 var(--font-head);
  letter-spacing: -.02em; margin: 0 0 16px; color: var(--ink);
  overflow-wrap: break-word;
}
.meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.meta__item { display: inline-flex; align-items: center; gap: 6px; }
.meta__item + .meta__item::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: #b3b9cc; margin-right: 12px; }

/* Framed images: fixed 16:9 frame, image centred and never stretched */
.figure {
  margin: 28px 0;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.figure--hero { margin-top: 0; }
.frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 10px;
  background: #e9edf6;
}
.frame img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
}
.figure figcaption { padding: 10px 6px 2px; font-size: 14px; line-height: 1.5; color: var(--muted); text-align: center; }

/* Table of contents */
.toc { margin: 8px 0 32px; padding: 20px 24px; background: #f7f8fc; border: 1px solid var(--line); border-radius: var(--radius); }
.toc__title { margin: 0 0 8px; font: 700 16px/1.3 var(--font-head); }
.toc ol { margin: 0; padding-left: 20px; columns: 2; column-gap: 32px; }
.toc li { break-inside: avoid; margin: 4px 0; font-size: 15px; line-height: 1.45; }
.toc a { color: var(--ink-2); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }

/* Prose */
.prose { font-size: 18px; color: #1f2742; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.15em; }
.prose h2 {
  font: 800 clamp(23px, 2.4vw, 29px)/1.25 var(--font-head);
  letter-spacing: -.015em; margin: 1.8em 0 .6em; color: var(--ink);
}
.prose h3 { font: 700 20px/1.35 var(--font-head); margin: 1.4em 0 .4em; color: var(--ink); }
.prose ul, .prose ol { margin: 0 0 1.3em; padding-left: 1.4em; }
.prose li { margin: .45em 0; }
.prose li::marker { color: var(--accent); font-weight: 700; }
.prose strong { color: var(--ink); }

.prose ol.factors { list-style: none; padding: 0; counter-reset: f; display: grid; gap: 12px; }
.prose ol.factors li {
  counter-increment: f; position: relative; margin: 0;
  padding: 16px 18px 16px 64px; background: #f7f8fc; border: 1px solid var(--line); border-radius: 14px;
}
.prose ol.factors li::before {
  content: counter(f); position: absolute; left: 16px; top: 16px;
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font: 800 16px/1 var(--font-head);
}
.prose ul.checklist { list-style: none; padding: 0; }
.prose ul.checklist li { position: relative; padding-left: 36px; }
.prose ul.checklist li::before {
  content: ""; position: absolute; left: 0; top: .3em; width: 22px; height: 22px; border-radius: 50%;
  background: var(--teal) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}

.prose blockquote {
  margin: 1.6em 0; padding: 22px 26px;
  background: linear-gradient(135deg, #eef2ff, #eafaf8);
  border-left: 4px solid var(--accent); border-radius: 0 14px 14px 0;
  font-style: italic; color: var(--ink-2);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.table-wrap { overflow-x: auto; margin: 0 0 1.4em; border: 1px solid var(--line); border-radius: 14px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 16px; min-width: 520px; }
.prose th, .prose td { padding: 12px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.prose thead th { background: var(--navy); color: #fff; font-weight: 600; }
.prose tbody tr:nth-child(even) { background: #f7f8fc; }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose td:first-child { font-weight: 600; color: var(--ink); }

/* Sidebar cards */
.sidebar__title { font: 800 20px/1.3 var(--font-head); margin: 0 0 14px; }
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  margin-bottom: 16px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(20, 26, 51, .05), 0 14px 32px rgba(20, 26, 51, .1); }
.frame--card { border-radius: 10px; }
.card__body { padding: 12px 8px 8px; }
.card__section { margin: 0 0 4px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--teal); }
.card__title { margin: 0 0 6px; font: 700 16px/1.35 var(--font-head); }
.card__title a { color: var(--ink); text-decoration: none; }
.card__title a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.card:hover .card__title a { color: var(--accent); }
.card__excerpt {
  margin: 0 0 8px; font-size: 14px; line-height: 1.5; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card__more { font-size: 14px; font-weight: 600; color: var(--accent); }

/* 404 */
.article--404 { text-align: center; padding: 64px 32px; }
.lead { font-size: 19px; color: var(--ink-2); max-width: 560px; margin: 0 auto 24px; }
.btn { display: inline-block; padding: 12px 22px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }
.btn:hover { background: var(--accent-ink); color: #fff; }

/* Footer */
.footer { background: var(--navy); color: #b9c2de; font-size: 15px; }
.footer__grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 40px; padding-top: 48px; padding-bottom: 32px; }
.logo--footer { color: #fff; margin-bottom: 16px; }
.logo--footer:hover { color: #fff; }
.logo--footer .logo__text small { color: #8f9ac0; }
.footer__about p { margin: 0 0 12px; line-height: 1.65; max-width: 560px; }
.footer__title { font: 700 15px/1.3 var(--font-head); color: #fff; margin: 4px 0 14px; letter-spacing: .02em; }
.footer ul { list-style: none; margin: 0; padding: 0; }
.footer li { margin: 0 0 8px; }
.footer a { color: #d6dcf0; text-decoration: none; }
.footer a:hover { color: #fff; text-decoration: underline; }
.footer__bottom {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px;
  border-top: 1px solid rgba(255, 255, 255, .12); padding-top: 20px; padding-bottom: 28px; font-size: 13px; color: #8f9ac0;
}
.footer__bottom p { margin: 0; }

/* Responsive */
@media (max-width: 1023px) {
  .sidebar { margin-top: 32px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .sidebar__title { grid-column: 1 / -1; margin-bottom: 0; }
  .card { margin-bottom: 0; }
  .header__inner { flex-wrap: wrap; gap: 8px 24px; padding-top: 12px; padding-bottom: 8px; }
  .nav { margin-left: 0; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav ul { padding-bottom: 4px; }
}
@media (max-width: 767px) {
  body { font-size: 16px; }
  .topbar__tagline { display: none; }
  .article { padding: 24px 18px 28px; border-radius: 18px; }
  .meta { flex-direction: column; gap: 2px; }
  .meta__item + .meta__item::before { display: none; }
  .prose { font-size: 17px; }
  .toc ol { columns: 1; }
  .figure { padding: 6px; margin: 22px 0; }
  .prose ol.factors li { padding: 14px 14px 14px 56px; }
  .prose ol.factors li::before { left: 12px; top: 14px; width: 30px; height: 30px; font-size: 14px; }
  .prose blockquote { padding: 18px; }
  .footer__grid { grid-template-columns: 1fr 1fr; gap: 28px; }
  .footer__about { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .sidebar { grid-template-columns: 1fr; }
  .layout { padding-top: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card { transition: none; }
}
