:root {
  --paper: #fafbfc;
  --panel: #f1f3f6;
  --ink: #172033;
  --muted: #535e70;
  --rule: #d9dee6;
  --accent: #0b6767;
  --accent-ink: #ffffff;
  --g-env: #4d5b73;
  --g-tbl: #6b4fa0;
  --g-val: #0b6767;
  --g-ptr: #a8375a;
  --g-sum: #8a5a00;
  --bad: #a8375a;
  --good: #0b6767;
  --term-bg: #1b2333;
  --term-ink: #e3e8f0;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121824;
    --panel: #1a2232;
    --ink: #e4e8ef;
    --muted: #a3adbd;
    --rule: #2c3647;
    --accent: #5cb8b2;
    --accent-ink: #0d1a1a;
    --g-env: #9fb0c8;
    --g-tbl: #b7a1e6;
    --g-val: #5cb8b2;
    --g-ptr: #ec8aa6;
    --g-sum: #e0b45c;
    --bad: #ec8aa6;
    --good: #5cb8b2;
    --term-bg: #0c111b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.6 var(--sans);
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
code, pre { font-family: var(--mono); font-size: 0.9em; }
:not(pre) > code { background: var(--panel); padding: 0.05em 0.3em; border-radius: 3px; }
h1, h2, h3 { line-height: 1.15; margin: 0; font-weight: 600; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 24px; }

:lang(zh-CN) { --sans: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
:lang(zh-CN) body { line-height: 1.75; }
:lang(zh-CN) .hero h1 { letter-spacing: 0; max-width: 11em; font-size: clamp(32px, 4.2vw, 48px); line-height: 1.25; }
:lang(zh-CN) .band h2 { letter-spacing: 0; }

/* Header */
.top { border-bottom: 1px solid var(--rule); }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; height: 64px; }
.wordmark { font: 600 24px/1 var(--mono); color: var(--ink); text-decoration: none; letter-spacing: -0.02em; display: inline-flex; align-items: center; gap: 10px; }
.mark { width: 26px; height: 26px; flex: none; }
.mark .mk-bg { fill: var(--ink); }
.mark .mk-l { fill: var(--paper); }
.mark .mk-a { fill: #5cb8b2; }
.top nav { display: flex; gap: 24px; flex-wrap: wrap; }
.top nav a { color: var(--muted); text-decoration: none; font-size: 15px; }
.top nav a:hover { color: var(--ink); }
.top-inner > nav:first-of-type { margin-left: auto; }
.langs { gap: 14px !important; padding-left: 24px; border-left: 1px solid var(--rule); }
.langs a { font-size: 14px !important; }
.langs a[aria-current="page"] { color: var(--ink) !important; font-weight: 500; }
.note { font-size: 14px; color: var(--muted); margin-top: 8px; }

/* Hero */
.hero { padding: 72px 0 80px; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 64px; align-items: start; }
.hero h1 { font-size: clamp(36px, 5vw, 56px); letter-spacing: -0.025em; max-width: 13ch; }
.lede { font-size: 19px; color: var(--muted); max-width: 34em; margin: 24px 0 16px; }
.lineage { font-size: 15px; color: var(--muted); max-width: 38em; margin: 0 0 32px; padding-left: 14px; border-left: 2px solid var(--accent); }
.lineage a { white-space: nowrap; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: 11px 20px; border-radius: 6px; font-weight: 500; font-size: 16px;
  text-decoration: none; border: 1px solid var(--rule); color: var(--ink); background: transparent;
}
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.status { margin-top: 28px; font-size: 14px; color: var(--muted); }

/* Anatomy diagram */
.anatomy { margin: 0; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 24px; }
.anatomy-title { font-weight: 600; font-size: 15px; margin-bottom: 16px; }
.schema { margin: 0 0 20px; font-size: 14px; line-height: 1.55; color: var(--muted); white-space: pre; overflow-x: auto; }
.schema .sl { border-radius: 3px; padding: 0 2px; transition: background-color .12s, color .12s; }
.anatomy.focus .schema .sl.on { color: var(--ink); background: color-mix(in srgb, var(--accent) 16%, transparent); }

.hex { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 4px 0; font: 500 14px/1 var(--mono); }
.byte {
  text-align: center; padding: 7px 0; color: var(--gc); position: relative;
  background: color-mix(in srgb, var(--gc) 9%, transparent);
  transition: opacity .12s, background-color .12s;
}
.byte.first { border-top-left-radius: 4px; border-bottom-left-radius: 4px; margin-left: 3px; }
.byte.last { border-top-right-radius: 4px; border-bottom-right-radius: 4px; margin-right: 3px; }
.g-env { --gc: var(--g-env); }
.g-tbl { --gc: var(--g-tbl); }
.g-val { --gc: var(--g-val); }
.g-ptr { --gc: var(--g-ptr); }
.g-sum { --gc: var(--g-sum); }
.anatomy.focus .byte { opacity: 0.28; }
.anatomy.focus .byte.on { opacity: 1; background: color-mix(in srgb, var(--gc) 22%, transparent); }

.explain { min-height: 3.2em; margin: 18px 0 14px; font-size: 15px; line-height: 1.5; }
.legend { list-style: none; margin: 0; padding: 14px 0 0; border-top: 1px solid var(--rule); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 12px; }
@media (max-width: 1100px) { .legend { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.legend button {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 13.5px; color: var(--muted);
}
.legend button:focus-visible { outline: 2px solid var(--accent); }
.legend button.on, .legend button:hover { color: var(--ink); background: color-mix(in srgb, var(--gc) 12%, transparent); }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; background: var(--gc); flex: none; }
.legend .nm { flex: 1; }
.legend .rg { font-family: var(--mono); font-size: 12px; opacity: 0.8; }

/* Sections */
.band { padding: 88px 0; border-top: 1px solid var(--rule); }
.band h2 { font-size: clamp(26px, 3vw, 34px); letter-spacing: -0.015em; max-width: 22ch; }
.section-head { max-width: 46em; margin-bottom: 40px; }
.section-head p { color: var(--muted); margin: 14px 0 0; font-size: 18px; }

.two { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 64px; }
.prose > p { margin: 0 0 28px; font-size: 18px; max-width: 36em; }
.points { margin: 0; }
.points dt { font-weight: 600; margin-top: 22px; }
.points dd { margin: 4px 0 0; color: var(--muted); max-width: 36em; }

.table-scroll { overflow-x: auto; }
.ledger { width: 100%; border-collapse: collapse; font-size: 16px; }
.ledger th, .ledger td { text-align: left; vertical-align: top; padding: 18px 24px 18px 0; border-top: 1px solid var(--rule); }
.ledger thead th { border-top: 0; font-size: 14px; font-weight: 500; color: var(--muted); padding-bottom: 10px; }
.ledger tbody th { width: 30%; font-weight: 600; padding-right: 32px; }
.ledger td { color: var(--muted); max-width: 46em; }

.evo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; }
.evo-label { font-weight: 600; margin: 0 0 10px; }
.code, .term { margin: 0 0 12px; padding: 18px 20px; border-radius: 8px; font-size: 14px; line-height: 1.6; overflow-x: auto; }
.code { background: var(--panel); border: 1px solid var(--rule); }
.term { background: var(--term-bg); color: var(--term-ink); }
mark { background: none; color: inherit; border-radius: 3px; padding: 0 2px; }
mark.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); }
mark.good { background: color-mix(in srgb, var(--good) 18%, transparent); }

.uses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 64px; margin: 0; }
.uses > div { padding: 22px 0; border-top: 1px solid var(--rule); }
.uses dt { font-weight: 600; font-size: 18px; }
.uses dd { margin: 6px 0 0; color: var(--muted); max-width: 34em; }

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 48px; }
.steps li { counter-increment: step; }
.steps h3 { font-size: 17px; margin-bottom: 12px; display: flex; gap: 12px; align-items: baseline; }
.steps h3::before { content: counter(step); font: 500 14px/1 var(--mono); color: var(--accent); }
.more { margin-top: 40px; color: var(--muted); }

.impls tbody th { width: 14%; }
.impls td:nth-child(2) { width: 26%; }
.two-text { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 48px; margin-top: 48px; }
.two-text h3 { font-size: 18px; margin-bottom: 8px; }
.two-text p { margin: 0; color: var(--muted); max-width: 36em; }

/* Footer */
.foot { border-top: 1px solid var(--rule); padding: 32px 0 48px; font-size: 14px; color: var(--muted); }
.foot-inner { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.foot p { margin: 0; }
.foot nav { display: flex; gap: 20px; flex-wrap: wrap; }
.foot a { color: var(--muted); }

@media (max-width: 960px) {
  .hero-grid, .two { grid-template-columns: 1fr; gap: 40px; }
  .hero { padding-top: 48px; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .wrap { padding: 0 16px; }
  .top-inner { height: auto; padding: 14px 16px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .top nav { gap: 16px; }
  .top-inner > nav:first-of-type { margin-left: 0; }
  .langs { padding-left: 0; border-left: 0; }
  .anatomy { padding: 16px; }
  .hex { grid-template-columns: repeat(8, minmax(0, 1fr)); font-size: 13px; }
  .evo, .uses, .steps, .two-text { grid-template-columns: 1fr; }
  .band { padding: 64px 0; }
  .ledger tbody th { width: auto; }
  .ledger, .ledger tbody, .ledger tr, .ledger th, .ledger td { display: block; }
  .ledger thead { display: none; }
  .ledger tbody th { padding-bottom: 4px; }
  .ledger td { border-top: 0; padding-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------------------------ documentation */
.top nav a[aria-current="page"] { color: var(--ink); font-weight: 500; }
.docs-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr) 210px; gap: 56px; padding-top: 48px; padding-bottom: 96px; align-items: start; }
.docs-nav, .docs-aside { position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow-y: auto; font-size: 14.5px; }
.docs-menu summary { font-weight: 600; font-size: 14px; color: var(--muted); cursor: default; list-style: none; margin-bottom: 8px; padding: 0 12px; pointer-events: none; }
.docs-menu summary::-webkit-details-marker { display: none; }
.docs-menu ul, .toc ul { list-style: none; margin: 0; padding: 0; }
.docs-menu ul { display: grid; gap: 2px; }
.docs-menu li a { display: block; padding: 6px 12px; line-height: 1.4; border-radius: 6px; color: var(--muted); text-decoration: none; }
.docs-menu li a:hover { color: var(--ink); background: var(--panel); }
.docs-menu li a[aria-current="page"] { color: var(--ink); background: var(--panel); font-weight: 500; box-shadow: inset 2px 0 0 var(--accent); }
.toc-title { font-weight: 600; font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.toc li a { display: block; padding: 4px 0; color: var(--muted); text-decoration: none; line-height: 1.4; }
.toc li a:hover { color: var(--accent); }

.doc { min-width: 0; max-width: 46em; font-size: 16.5px; line-height: 1.7; }
.doc h1 { font-size: clamp(30px, 3.4vw, 40px); letter-spacing: -0.02em; margin-bottom: 24px; }
.doc h2 { font-size: 25px; letter-spacing: -0.01em; margin: 56px 0 16px; padding-top: 28px; border-top: 1px solid var(--rule); scroll-margin-top: 16px; }
.doc h3 { font-size: 19px; margin: 36px 0 10px; scroll-margin-top: 16px; }
.doc h4 { font-size: 16.5px; margin: 28px 0 8px; }
.doc p, .doc ul, .doc ol { margin: 0 0 16px; }
.doc li { margin: 4px 0; }
.doc li > p { margin: 0; }
.doc hr { border: 0; border-top: 1px solid var(--rule); margin: 40px 0; }
.doc blockquote { margin: 0 0 16px; padding: 4px 0 4px 18px; border-left: 3px solid var(--rule); color: var(--muted); }
.doc .ref { font-size: 14px; color: var(--muted); padding-left: 14px; border-left: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); margin-top: -6px; }
.doc .ref code { font-size: 0.92em; }
.doc .code { margin: 0 0 20px; }
.doc .table-scroll { margin: 0 0 24px; }
.doc table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.5; }
.doc th, .doc td { text-align: left; vertical-align: top; padding: 9px 16px 9px 0; border-bottom: 1px solid var(--rule); }
.doc thead th { font-weight: 600; font-size: 13.5px; color: var(--muted); border-bottom: 1px solid var(--ink); }
.doc td code { white-space: nowrap; }
.doc td:last-child code { white-space: normal; }
.lede-doc { font-size: 18px; color: var(--muted); }
.doc-index { margin: 32px 0 0; }
.doc-index > div { padding: 18px 0; border-top: 1px solid var(--rule); }
.doc-index dt { font-weight: 600; font-size: 18px; }
.doc-index dt a { text-decoration: none; }
.doc-index dd { margin: 4px 0 0; color: var(--muted); }

/* Code highlighting (Pygments token classes) */
.code .c, .code .c1, .code .cm, .code .cs, .code .ch { color: var(--muted); font-style: italic; }
.code .sd { color: var(--g-env); font-style: italic; }
.code .k, .code .kd, .code .kn, .code .kr, .code .kc, .code .kp { color: var(--accent); }
.code .kt, .code .nc, .code .nn, .code .bp { color: var(--g-tbl); }
.code .s, .code .s1, .code .s2, .code .sb, .code .sc, .code .se, .code .sh, .code .si, .code .dl { color: var(--g-ptr); }
.code .m, .code .mi, .code .mh, .code .mf, .code .il, .code .nl { color: var(--g-sum); }
.code .nd, .code .na { color: var(--g-env); }
.code .nf, .code .fm { color: var(--ink); font-weight: 500; }
.code .o, .code .ow { color: var(--muted); }
.code .nb { color: var(--accent); }

@media (max-width: 1200px) {
  .docs-grid { grid-template-columns: 190px minmax(0, 1fr); }
  .docs-aside { display: none; }
}
@media (max-width: 960px) {
  .docs-grid { grid-template-columns: 1fr; gap: 24px; padding-top: 24px; }
  .docs-nav { position: static; max-height: none; }
  .docs-menu { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; }
  .docs-menu summary { cursor: pointer; margin: 0; padding: 0; list-style: revert; color: var(--ink); pointer-events: auto; }
  .docs-menu[open] summary { margin-bottom: 8px; }
  .doc td code { white-space: normal; }
}
.doc hr { display: none; }
.doc h1 code, .doc h2 code, .doc h3 code { background: none; padding: 0; font-size: 0.92em; }

/* Binary layout page: the hero diagram, one per example. */
.anatomy.layout { margin: 20px 0 36px; }
.anatomy.layout .schema { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 13px; }
.anatomy.layout .legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.anatomy.layout .legend .nm { overflow-wrap: anywhere; }
@media (max-width: 640px) { .anatomy.layout .legend { grid-template-columns: 1fr; } }
