:root {
  --ground: #E6EEEF;
  --face-0: #D2DDE1;
  --face-1: #BDCBD1;
  --face-2: #9FB8C2;
  --edge-dead: #8799A2;
  --edge-live: #3A545D;
  --ink: #132328;
  --ink-dim: #4E666E;
  --shift: #0C6B5C;
  --shift-deep: #094E44;
  --unit: 8px;
  --ui: -apple-system, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --display: -apple-system, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

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

html {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 13px;
  line-height: 16px;
  font-optical-sizing: auto;
  font-feature-settings: "tnum" 1, "liga" 1;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  min-height: 100vh;
}

a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  background: var(--face-2);
  text-decoration: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--shift);
}

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

/* Wordmark once */
.wordmark {
  font-family: var(--ui);
  font-size: 12px;
  line-height: 12px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  height: 32px;
}
.wordmark:hover {
  background: var(--face-2);
}

/* Cubist net header — shared edges, 0 gap, Wright band */
.chrome {
  display: flex;
  align-items: stretch;
  margin: 0;
  background: var(--face-1);
  border-bottom: 1px solid var(--edge-live);
  position: sticky;
  top: 0;
  z-index: 8;
}
.chrome a,
.chrome span {
  border-right: 1px solid var(--edge-dead);
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  height: 32px;
  text-decoration: none;
  color: var(--ink);
  font-size: 13px;
  line-height: 16px;
  letter-spacing: -0.018em;
}
.chrome a:last-child,
.chrome .grow {
  border-right: 0;
}
.chrome a[aria-current="page"] {
  background: var(--face-2);
}
.chrome .grow {
  flex: 1;
  border-right: 0;
}
.hole {
  width: 8px;
  height: 8px;
  margin: 12px 12px 12px 0;
  background: var(--ground);
  border: 0;
  flex: none;
  padding: 0;
  align-self: center;
}
.flip {
  width: 8px;
  height: 8px;
  margin: 12px 12px 12px 0;
  background: var(--shift);
  flex: none;
  padding: 0;
  align-self: center;
  border: 0;
}

.display {
  font-family: var(--display);
  font-size: 40px;
  line-height: 44px;
  font-weight: 500;
  letter-spacing: -0.052em;
  margin: 0;
}
.title {
  font-family: var(--display);
  font-size: 18px;
  line-height: 22px;
  font-weight: 500;
  letter-spacing: -0.028em;
  margin: 0 0 8px;
}
.meta {
  font-size: 11px;
  line-height: 14px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

/* Landing — copy left, lattice in the right third, 160px seam */
.landing {
  display: grid;
  grid-template-columns: minmax(0, 56ch) minmax(360px, 1fr);
  column-gap: 160px;
  max-width: 1280px;
  padding: 48px 48px 80px 24px;
  align-items: start;
}
.landing:not(:has(.lattice)) {
  display: block;
  max-width: 720px;
}
.landing .copy {
  max-width: 56ch;
  min-width: 0;
}
.landing .lede {
  font-size: 16px;
  line-height: 22px;
  max-width: 52ch;
  margin: 16px 0 24px;
}
.proof {
  font-size: 13px;
  line-height: 16px;
  color: var(--ink);
  margin: 0 0 24px;
  max-width: 56ch;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 12px 16px;
  background: var(--ink);
  color: var(--ground);
  text-decoration: none;
  border: 1px solid var(--ink);
  font-size: 13px;
  line-height: 16px;
  letter-spacing: -0.018em;
  max-width: 56ch;
  text-align: left;
}
.btn:hover {
  background: var(--edge-live);
  color: var(--ground);
}
.btn:focus-visible {
  box-shadow: inset 0 0 0 1px var(--shift);
}

.foot {
  border-top: 1px solid var(--edge-live);
  padding: 12px 24px 24px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 14px;
  letter-spacing: 0.04em;
}
.foot a {
  color: var(--ink-dim);
}

/* Lattice — visible shell, 12 cells including hole, rest 16/-24, right third */
.lattice {
  position: relative;
  width: 360px;
  height: 360px;
  justify-self: end;
  margin: 16px 0 0 0;
  perspective: 1400px;
  pointer-events: none;
}
.lattice-stage {
  position: absolute;
  top: 88px;
  left: 88px;
  width: 144px;
  height: 144px;
  transform-style: preserve-3d;
  transform: rotateX(16deg) rotateY(-24deg);
  animation: yaw 72s linear infinite;
  will-change: transform;
}
@keyframes yaw {
  from { transform: rotateX(16deg) rotateY(-24deg); }
  to { transform: rotateX(16deg) rotateY(336deg); }
}
.cell {
  position: absolute;
  width: 48px;
  height: 48px;
  transform-style: preserve-3d;
}
.face {
  position: absolute;
  display: block;
  margin: 0;
  top: 0;
  left: 0;
  font-style: normal;
  width: 48px;
  height: 48px;
  border: 1px solid var(--edge-dead);
}
.face-k {
  background: var(--face-2);
  transform: rotateY(90deg) translateZ(24px);
}
.face-b {
  background: var(--face-1);
  transform: translateZ(24px);
}
.face-s {
  background: var(--face-0);
  transform: rotateX(-90deg) translateZ(24px);
}
.cell-shift .face-b {
  background: var(--shift);
  border-color: var(--shift-deep);
}
.hole-cell {
  background: transparent;
  border: 0;
}
.hole-cell .face { display: none; }

/* positions: front 3x3 minus center (hole), plus 2 right + 1 top = 11 visible + hole */
.c00 { transform: translate3d(0px, 0px, 24px); }
.c10 { transform: translate3d(48px, 0px, 24px); }
.c20 { transform: translate3d(96px, 0px, 24px); }
.c01 { transform: translate3d(0px, 48px, 24px); }
.c11 { transform: translate3d(48px, 48px, 24px); } /* hole */
.c21 { transform: translate3d(96px, 48px, 24px); }
.c02 { transform: translate3d(0px, 96px, 24px); }
.c12 { transform: translate3d(48px, 96px, 24px); }
.c22 { transform: translate3d(96px, 96px, 24px); }
.c-r0 { transform: translate3d(96px, 0px, -24px); }
.c-r1 { transform: translate3d(96px, 96px, -24px); }
.c-t { transform: translate3d(0px, 0px, -24px); }

.cell-barrier {
  transition: transform 900ms cubic-bezier(0.4, 0, 0.2, 1);
}
body:has(.btn:hover) .cell-barrier,
body:has(.btn:focus-visible) .cell-barrier {
  transform: translate3d(96px, 0px, 24px);
}

/* Erosion chips — outer corners only, counts 5/7/9, offset table, not shift */
.chips {
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
}
.chips span {
  position: absolute;
  background: var(--face-0);
}
.chips span:nth-child(odd) {
  background: rgba(19, 35, 40, 0.28);
}
.chips span.w2 { width: 2px; height: 1px; }
.chips span.w1 { width: 1px; height: 1px; }
.chips span.h2 { width: 1px; height: 2px; }

.chips-tl { top: -1px; left: -1px; }
.chips-tr { top: -1px; right: -1px; }
.chips-bl { bottom: -1px; left: -1px; }
.chips-br { bottom: -1px; right: -1px; }

@media (prefers-reduced-motion: reduce) {
  .lattice-stage {
    animation: none;
    will-change: auto;
  }
  .cell-barrier { transition: none; }
}

@media (max-width: 960px) {
  .landing {
    grid-template-columns: 1fr;
    column-gap: 0;
    row-gap: 48px;
    padding: 24px 24px 64px;
  }
  .lattice {
    justify-self: start;
    margin: 0;
  }
}

/* Docs layout */
.docs {
  display: grid;
  grid-template-columns: 200px minmax(0, 65ch);
  gap: 0;
  align-items: start;
  max-width: 1080px;
}
.toc {
  position: sticky;
  top: 40px;
  padding: 16px 0 32px 24px;
  border-right: 1px solid var(--edge-dead);
  min-height: calc(100vh - 32px);
}
.toc a {
  display: block;
  padding: 4px 8px;
  text-decoration: none;
  color: var(--ink);
  border-right: 0;
}
.toc a:hover { background: var(--face-2); }
.toc .now {
  background: var(--face-2);
}
.toc .meta { margin: 0 0 8px; padding-left: 8px; }
article {
  padding: 24px 24px 64px;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: -0.018em;
  max-width: 65ch;
}
article h1 {
  font-family: var(--display);
  font-size: 40px;
  line-height: 44px;
  font-weight: 500;
  letter-spacing: -0.052em;
  margin: 0 0 8px;
}
article h2 {
  font-family: var(--display);
  font-size: 18px;
  line-height: 22px;
  font-weight: 500;
  letter-spacing: -0.028em;
  margin: 32px 0 8px;
}
article h3 {
  font-size: 13px;
  line-height: 16px;
  font-weight: 600;
  margin: 20px 0 8px;
}
article p { margin: 0 0 12px; }
article ul, article ol { margin: 0 0 12px; padding-left: 20px; }
article li { margin: 0 0 4px; }

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 8px 8px;
  height: 36px;
  border-bottom: 1px solid var(--edge-dead);
  vertical-align: top;
  font-weight: 400;
}
th {
  font-weight: 600;
  border-bottom: 1px solid var(--edge-live);
  background: var(--face-1);
}
tr:hover td { background: var(--face-2); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--face-1);
  border-bottom: 1px solid var(--edge-live);
  height: 36px;
}
.toolbar label {
  padding: 0 12px;
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.toolbar input[type="search"] {
  flex: 1;
  height: 36px;
  border: 0;
  border-left: 1px solid var(--edge-dead);
  background: var(--face-1);
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  border-radius: 0;
}
.toolbar input[type="search"]:hover { background: var(--face-2); }

.empty {
  padding: 24px;
  color: var(--ink-dim);
}

.pdf-frame {
  width: 100%;
  height: calc(100vh - 32px);
  border: 0;
  border-left: 1px solid var(--edge-dead);
  background: var(--face-0);
  display: block;
}
.pdf-wrap {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - 32px);
}
.pdf-side {
  padding: 16px 16px 32px;
  border-right: 1px solid var(--edge-dead);
}
.pdf-side p { line-height: 20px; }

.pager {
  display: flex;
  gap: 0;
  margin-top: 32px;
  border-top: 1px solid var(--edge-live);
}
.pager a {
  flex: 1;
  padding: 12px;
  text-decoration: none;
  border-right: 1px solid var(--edge-dead);
}
.pager a:last-child { border-right: 0; text-align: right; }
.pager a:hover { background: var(--face-2); }

@media (max-width: 720px) {
  .docs { grid-template-columns: 1fr; }
  .toc {
    position: relative;
    top: 0;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--edge-dead);
    padding: 8px 16px;
  }
  .pdf-wrap { grid-template-columns: 1fr; }
  .pdf-frame { height: 70vh; border-left: 0; border-top: 1px solid var(--edge-dead); }
}
