/* backtestmaxxing — a quant's notebook.
   After atalanta.tech: warm charcoal, a left rail split off by one full-height hairline,
   a light two-tone sentence instead of a headline, "/" navigation with a square marker.
   Switzer comes from Fontshare's CDN; IBM Plex Mono (OFL) is self-hosted in /fonts. */

@font-face { font-family: "IBM Plex Mono"; src: url("/fonts/ibm-plex-mono-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("/fonts/ibm-plex-mono-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --sans: "Switzer", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --rail: 240px;
  --pad: 20px;
  --measure: 700px;
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);
}

[data-theme="night"] {
  color-scheme: dark;
  --bg: #1a1917;
  --bg2: #242320;
  --bg3: #2e2d29;
  --ink: #f5f3ee;
  --accent: #f5f3ee;
  --muted: #bdb9ae;
  --dim: #a09c91;
  --hair: rgba(242, 240, 234, 0.14);
  --hair2: rgba(242, 240, 234, 0.28);
  --gain: #93cfa6;
  --loss: #e3907c;
  --grid: rgba(242, 240, 234, 0.08);
  --depth: rgba(242, 240, 234, 0.045);
}
[data-theme="paper"] {
  color-scheme: light;
  --bg: #f1efe9;
  --bg2: #e7e4dc;
  --bg3: #dcd8ce;
  --ink: #23221f;
  --accent: #23221f;
  --muted: #58544c;
  --dim: #665f56;
  --hair: rgba(35, 34, 31, 0.14);
  --hair2: rgba(35, 34, 31, 0.3);
  --gain: #25683f;
  --loss: #a23c27;
  --grid: rgba(35, 34, 31, 0.08);
  --depth: rgba(35, 34, 31, 0.035);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(var(--hair), var(--hair)) var(--rail) 0 / 1px 100% no-repeat,
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}
::selection { background: var(--ink); color: var(--bg); }
a { color: inherit; }
b, strong { font-weight: 600; }
.up { color: var(--gain); }
.down { color: var(--loss); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip { position: absolute; left: 12px; top: -60px; z-index: 30; padding: 8px 12px; background: var(--ink); color: var(--bg); text-decoration: none; }
.skip:focus { top: 12px; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }

/* ---------------- top bar ---------------- */

.top {
  display: grid;
  grid-template-columns: var(--rail) 1fr auto;
  align-items: stretch;
  min-height: 56px;
  border-bottom: 1px solid var(--hair);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.mark {
  display: flex; align-items: center; gap: 10px;
  padding: 0 var(--pad);
  font-size: 13px; letter-spacing: 0.01em; text-transform: none;
  text-decoration: none;
}
.mark .sq { width: 9px; height: 9px; background: var(--ink); }
.nav { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 0; padding: 0 var(--pad); color: var(--muted); }
.nav a { text-decoration: none; }
.nav a::before { content: "/"; margin: 0 14px 0 12px; color: var(--dim); }
.nav a:first-child::before { margin-left: 0; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.nav a[aria-current="page"]::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-bottom: 1px; margin-right: 9px; background: var(--ink); vertical-align: middle; }
.cells { display: flex; }
.cell {
  display: flex; align-items: center; gap: 10px;
  padding: 0 22px;
  border: 0; border-left: 1px solid var(--hair);
  background: var(--bg2); color: var(--ink);
  font: inherit; letter-spacing: inherit; text-transform: inherit;
  cursor: pointer;
}
.cell:hover { background: var(--bg3); }
kbd { font-family: var(--mono); font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.toggle .dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--ink); }
[data-theme="paper"] .toggle .dot { background: var(--ink); }
.toggle .lbl { color: var(--muted); }

/* the tape: what used to be a ticker, now a quiet status line */
.tape {
  margin-left: var(--rail);
  overflow: hidden;
  border-bottom: 1px solid var(--hair);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
}
.tape-track { display: inline-flex; animation: tape 160s linear infinite; will-change: transform; }
.tape .set { display: inline-flex; gap: 2.4rem; padding: 7px 2.4rem 7px 0; }
.tape:hover .tape-track { animation-play-state: paused; }
.tape b { font-weight: 400; color: var(--muted); }
.tape .up { color: var(--gain); }
.tape .down { color: var(--loss); }
@keyframes tape { to { transform: translate3d(-50%, 0, 0); } }

/* ---------------- rows: rail + body ---------------- */

main { padding-bottom: 80px; }
.row { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); border-bottom: 1px solid var(--hair); }
.row > .rail { padding: 34px var(--pad); font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.row > .body { padding: 34px var(--pad) 56px calc(var(--pad) + 1px); min-width: 0; max-width: 1080px; }
main > .row:last-child { border-bottom: 0; }

.label { margin: 0 0 6px; color: var(--ink); text-transform: uppercase; letter-spacing: 0.06em; }
.label span { color: var(--dim); margin-right: 8px; }
.rail-note { margin: 0; line-height: 1.6; }
.rail-note a { text-decoration: none; color: var(--ink); }
.rail-note a:hover { text-decoration: underline; text-underline-offset: 3px; }

.kv { margin: 0; }
.kv > div, .memo-meta > span {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dotted var(--hair2);
}
.kv dt { color: var(--dim); }
.kv dd { margin: 0; color: var(--ink); text-align: right; }
.kv dd.up { color: var(--gain); }
.kv dd.down { color: var(--loss); }
.memo-meta { position: sticky; top: 20px; }
.memo-meta > span { color: var(--dim); text-transform: lowercase; }
.memo-meta b { font-weight: 400; color: var(--ink); text-align: right; text-transform: none; }
.memo-meta b.up { color: var(--gain); }
.memo-meta b.down { color: var(--loss); }

.kicker { margin: 0 0 14px; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ---------------- front page ---------------- */

.hero > .body { padding-top: 72px; padding-bottom: 72px; }
.name { margin: 0 0 40px; font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.lede {
  max-width: 900px;
  margin: 0;
  font-size: clamp(30px, 3.6vw, 46px);
  font-weight: 300;
  line-height: 1.14;
  letter-spacing: -0.02em;
}
.lede span { color: var(--dim); }
.sub { max-width: 520px; margin: 30px 0 0; color: var(--muted); font-size: 16px; font-weight: 500; }

.sheet { margin: 0; border: 1px solid var(--hair); background: var(--bg2); }
.sheet-head {
  display: flex; flex-wrap: wrap; gap: 6px 28px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--hair);
  font-family: var(--mono); font-size: 11.5px; color: var(--dim);
}
.sheet-head b { font-weight: 400; color: var(--ink); }
.sheet-head b.up { color: var(--gain); }
.sheet-fig { padding: 18px 16px 4px; }
.sheet-fig svg { display: block; width: 100%; height: auto; overflow: visible; }
.sheet-foot { padding: 10px 16px; border-top: 1px solid var(--hair); font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
.area { fill: var(--ink); opacity: 0.05; }
.curve-path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 1400;
  stroke-dashoffset: 1400;
  animation: draw 2.2s var(--ease) 0.2s forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
.anno { font-family: var(--mono); font-size: 11px; fill: var(--muted); }
.anno.up { fill: var(--gain); }
.anno.down { fill: var(--loss); }
.pulse { fill: none; stroke: var(--gain); animation: ping 2.4s ease-out infinite; }
@keyframes ping { 0% { r: 4; opacity: 0.8; } 100% { r: 13; opacity: 0; } }
.axis { font-family: var(--mono); font-size: 10.5px; fill: var(--dim); }
.gridline { stroke: var(--grid); stroke-width: 1; }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin-top: -1px; border: 1px solid var(--hair); border-top: 0; }
.stat { display: grid; align-content: start; gap: 6px; padding: 14px 14px 16px; border-left: 1px solid var(--hair); }
.stat:first-child { border-left: 0; }
.stat .v { font-family: var(--mono); font-size: 20px; line-height: 1; }
.stat .k { font-size: 12.5px; line-height: 1.35; color: var(--muted); }

/* ---------------- the book: memos as an order book ---------------- */

.book { width: 100%; border-collapse: collapse; font-size: 15px; }
.book th {
  padding: 0 14px 9px 0;
  border-bottom: 1px solid var(--hair2);
  font-family: var(--mono); font-size: 11px; font-weight: 400; color: var(--dim);
  text-align: left; text-transform: lowercase;
}
.book td { padding: 16px 14px 16px 0; border-bottom: 1px solid var(--hair); vertical-align: baseline; }
.book .num { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.book th.num { font-size: 11px; }
.book .t-size { text-align: right; padding-right: 10px; }
.book tbody tr {
  position: relative;
  background: linear-gradient(var(--depth), var(--depth)) right / calc(var(--size, 0) * 100%) 100% no-repeat;
}
.t-memo a { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; text-decoration: none; }
.t-memo a::after { content: ""; position: absolute; inset: 0; }
.t-sub { display: block; margin-top: 3px; font-size: 14px; color: var(--muted); }
.t-conf { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.book tbody tr:hover { background-color: var(--bg2); }
.book tbody tr:hover .t-memo a { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }

/* ---------------- memo pages ---------------- */

.memo > .body { padding-top: 56px; }
.memo h1 { max-width: 860px; margin: 0 0 34px; font-size: clamp(30px, 3.4vw, 44px); font-weight: 300; line-height: 1.1; letter-spacing: -0.02em; }

.prose { max-width: var(--measure); font-size: 18px; line-height: 1.62; }
.prose p { margin: 0 0 1.1em; hyphens: auto; }
.prose a { text-decoration-color: var(--hair2); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose a:hover { text-decoration-color: var(--ink); }
.prose h2 { margin: 2.2em 0 0.7em; font-size: 22px; font-weight: 500; letter-spacing: -0.01em; }
.prose blockquote { margin: 1.8em 0; padding: 4px 0 4px 20px; border-left: 1px solid var(--ink); }
.prose blockquote p { margin: 0; font-size: 21px; font-weight: 300; line-height: 1.4; }
.prose em { font-style: italic; }
.drop::first-line { font-weight: 500; }
code { font-family: var(--mono); font-size: 0.82em; padding: 1px 5px; background: var(--bg2); }

.tbl { width: 100%; margin: 1.8em 0; border-collapse: collapse; font-size: 14px; }
.tbl caption { caption-side: top; padding-bottom: 10px; text-align: left; font-family: var(--mono); font-size: 11.5px; line-height: 1.5; color: var(--muted); }
.tbl th { padding: 8px 12px 8px 0; border-top: 1px solid var(--hair2); border-bottom: 1px solid var(--hair2); font-family: var(--mono); font-size: 11px; font-weight: 400; color: var(--dim); text-align: left; }
.tbl td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--hair); font-family: var(--mono); font-size: 13px; }
.tbl tbody tr:hover td { background: var(--bg2); }
.tbl tfoot td { font-size: 11px; color: var(--dim); border-bottom: 0; }

.afterword { max-width: var(--measure); margin: 48px 0 0; border: 1px solid var(--hair); background: var(--bg2); font-family: var(--mono); font-size: 12.5px; }
.afterword .kicker { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--hair); color: var(--ink); }
.afterword .row { display: flex; justify-content: space-between; gap: 18px; padding: 8px 14px; border-bottom: 1px dotted var(--hair2); }
.afterword .row:last-child { border-bottom: 0; }
.afterword .row span:first-child { color: var(--dim); }
.afterword .row span:last-child { text-align: right; }
.afterword b { font-weight: 500; }

.pager {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px;
  max-width: var(--measure);
  margin-top: 40px; padding-top: 14px;
  border-top: 1px solid var(--hair);
  font-family: var(--mono); font-size: 12px;
}
.pager > :last-child { text-align: right; }
.pager > :nth-child(2) { text-align: center; }
.pager a { text-decoration: none; color: var(--muted); }
.pager a:hover { color: var(--ink); }
.pager span { color: var(--dim); }

/* ---------------- projects: positions ---------------- */

.cards { margin-top: 48px; border-top: 1px solid var(--hair2); }
.card {
  display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 8px 40px;
  padding: 26px 0 30px;
  border-bottom: 1px solid var(--hair);
}
.card-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.card h2 { margin: 0; font-family: var(--mono); font-size: 17px; font-weight: 500; }
.card-body { display: contents; }
.card-body p { grid-column: 1; margin: 6px 0 0; max-width: 620px; color: var(--muted); }
.card-body a { text-underline-offset: 3px; text-decoration-color: var(--hair2); }
.metrics { grid-column: 2; grid-row: 2; display: grid; align-content: start; font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
.metrics span { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dotted var(--hair2); }
.metrics b { font-weight: 400; color: var(--ink); }
.metrics b.up { color: var(--gain); }
.metrics b.down { color: var(--loss); }
.spark { grid-column: 2; margin: 10px 0 0; display: flex; align-items: center; gap: 12px; }
.spark svg { width: 120px; height: 36px; flex: none; }
.spark polyline { stroke-width: 1.5; }
.spark figcaption { font-family: var(--mono); font-size: 11px; color: var(--dim); }

.chip { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.chip::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 7px; background: currentColor; vertical-align: 1px; }
.chip.warm { color: var(--ink); }
.chip.live { color: var(--gain); }
.chip.dead { color: var(--loss); }

/* ---------------- 404 ---------------- */

.lost > .body { padding-top: 64px; max-width: 820px; }
.lost .big { margin: 0 0 10px; font-family: var(--mono); font-size: 56px; font-weight: 400; line-height: 1; }
.lost .why { margin: 10px 0; color: var(--muted); }
.lost .big + .why { font-family: var(--mono); font-size: 13px; color: var(--loss); }
.lost svg { display: block; width: 100%; margin: 28px 0; }
.board { max-width: 460px; margin: 0 0 30px; border-top: 1px solid var(--hair2); font-family: var(--mono); font-size: 12.5px; }
.board .row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dotted var(--hair2); }
.board .row span:first-child { color: var(--dim); }
.board i { display: inline-block; width: 6px; height: 6px; margin-right: 8px; background: currentColor; animation: blink 1.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.back {
  display: inline-block;
  padding: 11px 18px;
  border: 1px solid var(--hair2);
  background: var(--bg2);
  font-size: 12px; font-weight: 500; letter-spacing: 0.06em;
  text-decoration: none;
}
.back:hover { background: var(--bg3); }

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

.site-foot { border-top: 1px solid var(--hair); padding: 40px var(--pad) 28px calc(var(--rail) + var(--pad) + 1px); font-size: 14px; }
.foot-cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px; max-width: 1080px; }
.foot-cols > div { display: flex; flex-direction: column; gap: 5px; }
.foot-cols a { width: fit-content; text-decoration: none; color: var(--muted); }
.foot-cols a:hover { color: var(--ink); }
.foot-cols span { color: var(--dim); }
.foot-cols b { font-family: var(--mono); font-weight: 400; color: var(--ink); }
.foot-h { margin: 0 0 6px; font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.foot-grid, .foot-note { margin: 0; font-family: var(--mono); font-size: 11px; color: var(--dim); }
.foot-grid { margin-top: 44px; padding-top: 12px; border-top: 1px solid var(--hair); }
.foot-note { margin-top: 6px; padding-bottom: env(safe-area-inset-bottom); }

/* ---------------- ⌘K index ---------------- */

.cmdk {
  width: min(580px, 100% - 32px);
  margin: 12vh auto auto;
  padding: 0;
  border: 1px solid var(--hair2);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.cmdk::backdrop { background: rgba(20, 19, 17, 0.55); }
.cmdk-box { margin: 0; }
.cmdk input {
  width: 100%;
  padding: 16px 18px;
  border: 0;
  border-bottom: 1px solid var(--hair2);
  background: transparent;
  color: inherit;
  font-family: var(--mono);
  font-size: 16px;
  outline: none;
}
.cmdk ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.cmdk li > * {
  display: flex; justify-content: space-between; gap: 14px; width: 100%;
  padding: 9px 12px;
  border: 0; background: none; color: inherit;
  font: inherit; font-size: 15px; text-align: left; text-decoration: none;
  cursor: pointer;
}
.cmdk li span { font-family: var(--mono); font-size: 11.5px; color: var(--dim); white-space: nowrap; }
.cmdk li.on > * { background: var(--bg2); box-shadow: inset 2px 0 0 var(--ink); }
.cmdk-foot { margin: 0; padding: 9px 16px; border-top: 1px solid var(--hair); font-family: var(--mono); font-size: 11px; color: var(--dim); }
.cmdk-foot kbd { margin-right: 3px; }

/* ---------------- small screens ---------------- */

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat:nth-child(4) { border-left: 0; }
  .stat:nth-child(n+4) { border-top: 1px solid var(--hair); }
}
@media (max-width: 860px) {
  :root { --rail: 0px; --pad: 18px; }
  body { background: var(--bg); }
  .top { grid-template-columns: 1fr auto; }
  .mark { padding: 14px var(--pad); }
  .nav { grid-column: 1 / -1; grid-row: 2; padding: 10px var(--pad); border-top: 1px solid var(--hair); }
  .cells { grid-column: 2; grid-row: 1; }
  .cell { padding: 0 14px; }
  .toggle .lbl, .cell kbd { display: none; }
  .row { grid-template-columns: 1fr; }
  .row > .rail { padding: 18px var(--pad) 0; }
  .row > .body { padding: 18px var(--pad) 44px; }
  .hero > .body { padding-top: 28px; padding-bottom: 48px; }
  .kv { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
  .memo-meta { position: static; display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
  .memo > .body { padding-top: 28px; }
  .name { margin-bottom: 22px; }
  .card { grid-template-columns: 1fr; }
  .metrics, .spark { grid-column: 1; grid-row: auto; }
  .metrics { margin-top: 12px; }
  .site-foot { padding-left: var(--pad); }
  .foot-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(n) { border-left: 1px solid var(--hair); border-top: 1px solid var(--hair); }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(-n+2) { border-top: 0; }
  .book thead, .book .t-date, .book .t-conf { display: none; }
  .book td { padding: 14px 10px 14px 0; }
  .book .t-size { vertical-align: top; padding-top: 18px; }
  .prose { font-size: 17px; }
  .pager { grid-template-columns: 1fr; }
  .pager > * { text-align: left !important; }
  .afterword .row { flex-direction: column; gap: 2px; }
  .afterword .row span:last-child { text-align: left; }
  .sheet-head { gap: 4px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .curve-path { stroke-dashoffset: 0; }
  html { scroll-behavior: auto; }
}
