/* =========================================================
   CSS Development Lab 13
   Sticky Header / Sticky Sidebar
   ========================================================= */

:root {
  --page-max: 1200px;
  --header-h: 72px;
  --text: #171717;
  --muted: #686868;
  --line: #e5e5df;
  --surface: #ffffff;
  --soft: #f5f5f1;
  --dark: #171717;
  --radius: 20px;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 26px);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--surface);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  line-height: 1.7;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.page-wrap {
  width: min(calc(100% - 40px), var(--page-max));
  margin-inline: auto;
}

.eyebrow {
  margin: 0 0 14px;
  color: #858585;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .15em;
}

/* ---------- Sticky header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px);
}

.header-inner {
  width: min(calc(100% - 40px), var(--page-max));
  height: 100%;
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 30px;
}

.brand {
  font-weight: 850;
  letter-spacing: -.02em;
}

.top-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 22px;
}

.top-nav a {
  font-size: .9rem;
  font-weight: 700;
  color: #555;
}

/* ---------- Intro ---------- */

.intro {
  padding: clamp(72px, 10vw, 130px) 0 clamp(60px, 8vw, 100px);
  background:
    radial-gradient(circle at 86% 14%, rgba(0,0,0,.05), transparent 27%),
    linear-gradient(180deg, #fafaf8 0%, #f3f3ef 100%);
}

.intro-inner {
  max-width: 1000px;
}

.intro h1,
.article h2,
.summary h2 {
  margin: 0;
  line-height: 1.04;
  letter-spacing: -.045em;
}

.intro h1 {
  font-size: clamp(2.8rem, 7vw, 6rem);
}

.intro-desc {
  max-width: 820px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.7vw, 1.18rem);
}

/* ---------- Docs layout ---------- */

.docs-layout {
  padding: clamp(80px, 10vw, 130px) 0;
}

.docs-grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  align-items: stretch;
  gap: clamp(44px, 8vw, 110px);
}

.sidebar {
  min-width: 0;
  /* Must stretch with the Grid row so the sticky child has room to travel. */
}

.sidebar-sticky {
  position: sticky;
  top: calc(var(--header-h) + 24px);
}

.sidebar-title {
  margin: 0 0 14px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.toc {
  display: grid;
  border-top: 1px solid var(--line);
}

.toc a {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  color: #555;
  font-size: .88rem;
  transition: color 160ms ease, transform 160ms ease;
}

.toc a:hover {
  color: var(--text);
  transform: translateX(3px);
}

.sidebar-note {
  margin-top: 22px;
  padding: 16px;
  display: grid;
  gap: 4px;
  border-radius: 14px;
  background: var(--soft);
}

.sidebar-note strong {
  font-size: .84rem;
}

.sidebar-note span {
  color: var(--muted);
  font-size: .8rem;
}

/* ---------- Article ---------- */

.article {
  min-width: 0;
  max-width: 820px;
}

.article section {
  padding: 0 0 clamp(80px, 9vw, 120px);
}

.article section:last-child {
  padding-bottom: 0;
}

.article h2 {
  font-size: clamp(2rem, 4vw, 4rem);
}

.article p:not(.eyebrow) {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.code-card {
  margin-top: 28px;
  overflow-x: auto;
  border-radius: 16px;
  background: #181818;
}

.code-card pre {
  margin: 0;
  padding: 24px;
}

.code-card code {
  color: #f2f2f2;
  line-height: 1.75;
}

.diagram {
  margin-top: 28px;
  display: grid;
  justify-items: start;
  gap: 8px;
}

.diagram div {
  min-width: 230px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
  font-weight: 750;
}

.diagram span {
  padding-left: 105px;
  color: #999;
}

.problem-grid {
  margin-top: 30px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.problem-grid article {
  min-height: 200px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.problem-grid span {
  color: #999;
  font-size: .76rem;
  font-weight: 800;
}

.problem-grid h3 {
  margin: auto 0 8px;
  font-size: 1.15rem;
}

.problem-grid p {
  margin: 0 !important;
  font-size: .9rem !important;
}

.compare-box {
  margin-top: 28px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.compare-box > div {
  padding: 20px;
  display: grid;
  gap: 10px;
  border-radius: 14px;
  background: var(--soft);
}

.compare-box strong {
  font-size: .88rem;
}

.compare-box code {
  overflow-wrap: anywhere;
  font-size: .82rem;
}

.usage-list {
  margin-top: 28px;
  display: grid;
  border-top: 1px solid var(--line);
}

.usage-list > div {
  padding: 18px 0;
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.usage-list strong {
  font-size: .92rem;
}

.usage-list span {
  color: var(--muted);
}

/* ---------- Summary ---------- */

.summary {
  padding: 0 0 clamp(90px, 12vw, 150px);
}

.summary-grid {
  padding: clamp(30px, 6vw, 64px);
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(320px, 1.15fr);
  align-items: center;
  gap: clamp(36px, 7vw, 90px);
  border-radius: 28px;
  background: var(--soft);
}

.summary h2 {
  font-size: clamp(2rem, 4.5vw, 4.5rem);
}

.summary ol {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 14px;
}

.summary li {
  color: #505050;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .docs-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .article {
    max-width: none;
  }
}

@media (max-width: 700px) {
  .page-wrap,
  .header-inner {
    width: calc(100% - 28px);
  }

  .top-nav {
    display: none;
  }

  .problem-grid,
  .compare-box {
    grid-template-columns: 1fr;
  }

  .usage-list > div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .summary-grid {
    padding: 24px;
  }
}

:focus-visible {
  outline: 2px solid #171717;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
  }
}
