:root {
  --bg: #fcfbf8;
  --surface: #f5f3ed;
  --fg: #17160f;
  --muted: #6c6a5f;
  --faint: #918e82;
  --line: #e4e1d8;
  --line-strong: #cdc9bd;
  --accent: #a8432a;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121210;
    --surface: #1b1a17;
    --fg: #eae8df;
    --muted: #8f8c80;
    --faint: #74716a;
    --line: #292824;
    --line-strong: #3d3b34;
    --accent: #e2795a;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.75;
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 24px;
  top: 16px;
  z-index: 10;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
}

/* ---------- masthead ---------- */

.masthead {
  border-bottom: 1px solid var(--line);
}

.masthead-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 32px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
}

.wordmark {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.stamp {
  font-size: 0.78rem;
  color: var(--faint);
  letter-spacing: 0.02em;
}

/* ---------- shell ---------- */

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 32px 96px;
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: 72px;
}

.shell-wide {
  display: block;
}

.toc {
  padding-top: 56px;
}

.toc-sticky {
  position: sticky;
  top: 40px;
}

.toc-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 14px;
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc li + li {
  margin-top: 2px;
}

.toc a {
  display: flex;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted);
  text-decoration: none;
}

.toc a:hover {
  color: var(--fg);
}

.toc a[aria-current="page"] {
  color: var(--fg);
  font-weight: 600;
}

.toc-num {
  font-family: var(--serif);
  font-size: 0.8rem;
  color: var(--faint);
  min-width: 1.4em;
}

.toc a[aria-current="page"] .toc-num {
  color: var(--accent);
}

/* ---------- article ---------- */

.doc {
  padding-top: 56px;
  max-width: 68ch;
}

.eyebrow {
  font-family: var(--serif);
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}

h1 {
  font-size: 2rem;
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 20px;
}

.lede {
  font-size: 1.12rem;
  line-height: 1.7;
  color: var(--fg);
  margin: 0 0 8px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

h2 {
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.5;
  margin: 52px 0 14px;
}

h3 {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 32px 0 10px;
}

p {
  margin: 0 0 18px;
}

.doc ul,
.doc ol {
  margin: 0 0 18px;
  padding-left: 1.25em;
}

.doc li {
  margin-bottom: 8px;
}

.doc li::marker {
  color: var(--faint);
}

strong {
  font-weight: 600;
}

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 3px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.88rem;
  line-height: 1.65;
}

/* ---------- callout ---------- */

.note {
  margin: 28px 0;
  padding: 2px 0 2px 20px;
  border-left: 2px solid var(--accent);
}

.note p:last-child {
  margin-bottom: 0;
}

.note-label {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

/* ---------- table ---------- */

.table-wrap {
  margin: 26px 0;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  line-height: 1.6;
}

th,
td {
  text-align: left;
  padding: 11px 16px 11px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

thead th {
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 9px;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

td:first-child {
  font-weight: 500;
  white-space: nowrap;
  padding-right: 24px;
}

/* ---------- signal groups ---------- */

.group {
  margin: 22px 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.group-name {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.group-meta {
  font-size: 0.78rem;
  color: var(--faint);
  white-space: nowrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chips li {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--muted);
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- strength meter ---------- */

.meter {
  margin: 26px 0;
}

.meter-row {
  display: grid;
  grid-template-columns: 4.5em 1fr;
  align-items: start;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.meter-row:last-child {
  border-bottom: none;
}

.meter-level {
  font-size: 0.8rem;
  color: var(--muted);
  padding-top: 1px;
}

.meter-bar {
  display: block;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin-top: 7px;
}

.meter-items {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--muted);
}

.meter-items code {
  color: var(--fg);
}

/* ---------- flow diagram ---------- */

.flow {
  margin: 48px 0 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: stretch;
  gap: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.flow-col {
  padding: 26px 24px;
}

.flow-col + .flow-col {
  border-left: 1px solid var(--line);
}

.flow-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  color: var(--line-strong);
  font-size: 0.9rem;
}

.flow-title {
  font-size: 0.72rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 16px;
}

.flow-item {
  margin-bottom: 16px;
}

.flow-item:last-child {
  margin-bottom: 0;
}

.flow-name {
  font-size: 0.92rem;
  font-weight: 600;
  margin: 0 0 2px;
}

.flow-desc {
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--muted);
  margin: 0;
}

.flow-tag {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 7px;
  margin-top: 6px;
  line-height: 1.7;
}

.flow-caption {
  font-size: 0.83rem;
  color: var(--faint);
  margin: 14px 0 0;
}

/* ---------- home ---------- */

.hero {
  max-width: 780px;
  padding: 88px 0 0;
}

.hero h1 {
  font-size: clamp(1.9rem, 1.2rem + 2.4vw, 2.9rem);
  line-height: 1.28;
  letter-spacing: -0.022em;
  margin-bottom: 24px;
}

.hero-sub {
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--muted);
  max-width: 62ch;
  margin: 0;
}

.cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 40px;
  padding: 11px 22px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.cta:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.home-index {
  margin: 88px 0 0;
  border-top: 1px solid var(--line);
}

.home-index a {
  display: grid;
  grid-template-columns: 3em minmax(0, 1fr);
  gap: 20px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.home-index a:hover .home-title {
  color: var(--accent);
}

.home-num {
  font-family: var(--serif);
  font-size: 0.88rem;
  color: var(--faint);
  padding-top: 2px;
}

.home-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 3px;
  transition: color 0.15s ease;
}

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

/* ---------- pager ---------- */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 72px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}

.pager a {
  text-decoration: none;
  color: var(--muted);
  max-width: 46%;
}

.pager a:hover {
  color: var(--accent);
}

.pager-dir {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 3px;
}

.pager-next {
  text-align: right;
  margin-left: auto;
}

/* ---------- footer ---------- */

.foot {
  border-top: 1px solid var(--line);
  margin-top: 0;
}

.foot-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 32px 48px;
  font-size: 0.82rem;
  color: var(--faint);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
}

/* ---------- sources ---------- */

.sources {
  list-style: none;
  margin: 26px 0 0;
  padding: 0;
}

.sources li {
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  line-height: 1.6;
}

.sources a {
  font-weight: 500;
  display: block;
}

.sources span {
  display: block;
  color: var(--faint);
  font-size: 0.82rem;
  word-break: break-all;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  body {
    font-size: 16px;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0 22px 72px;
  }

  .masthead-inner,
  .foot-inner {
    padding-left: 22px;
    padding-right: 22px;
  }

  .toc {
    padding-top: 22px;
    margin: 0 -22px;
    border-bottom: 1px solid var(--line);
  }

  .toc-sticky {
    position: static;
  }

  .toc-label {
    display: none;
  }

  .toc ol {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 0 22px 14px;
    scrollbar-width: none;
  }

  .toc ol::-webkit-scrollbar {
    display: none;
  }

  .toc li + li {
    margin-top: 0;
  }

  .toc a {
    padding: 4px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
    font-size: 0.84rem;
  }

  .toc a[aria-current="page"] {
    border-color: var(--accent);
    color: var(--accent);
  }

  .toc a[aria-current="page"] .toc-num {
    color: inherit;
  }

  .doc {
    padding-top: 36px;
  }

  .hero {
    padding-top: 52px;
  }

  .flow {
    grid-template-columns: minmax(0, 1fr);
  }

  .flow-col + .flow-col {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .flow-arrow {
    padding: 10px 0;
    transform: rotate(90deg);
  }

  .meter-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .meter-bar {
    margin-top: 4px;
  }

  td:first-child {
    white-space: normal;
  }
}

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@media print {
  .toc,
  .pager,
  .masthead,
  .foot {
    display: none;
  }

  .shell {
    display: block;
    padding: 0;
  }
}
