/* Style overrides for standalone Distill posts.
   Mirrors al-folio's distill layout as used on alexzhang13.github.io
   (Roboto, wide text column spanning grid columns 3/-3, boxed TOC,
   tightened title padding). Light theme only. */

:root {
  --global-bg-color: #ffffff;
  --global-card-bg-color: #ffffff; /* Distill's hover boxes */
  --global-text-color: #000000;
  --global-text-color-light: #828282;
  --global-theme-color: #1772d0;   /* link color, matches the homepage */
  --global-hover-color: #f09228;   /* hover color, matches the homepage */
  --global-divider-color: rgba(0, 0, 0, 0.1);
  --global-distill-app-color: #828282;
  --global-code-bg-color: rgba(181, 9, 172, 0.05);
}

body {
  margin: 0;
  background-color: var(--global-bg-color);
  color: var(--global-text-color);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.5;
}

/* Small "back home" link above the title */
.site-nav {
  max-width: 1072px;
  margin: 0 auto;
  padding: 1rem 1rem 0;
  font-size: 0.9rem;
}
.site-nav a {
  color: var(--global-text-color-light);
  text-decoration: none;
  border-bottom: none;
}
.site-nav a:hover {
  color: var(--global-hover-color);
}

/* Title block: tighten Distill's 4rem padding */
d-title {
  padding-top: 1.25rem !important;
  padding-bottom: 1rem !important;
}
d-title h1 {
  font-size: 35px !important;
}
d-title p {
  font-size: 1.0rem !important;
}
@media (min-width: 768px) {
  d-title {
    padding-top: 1.5rem !important;
    padding-bottom: 1.25rem !important;
  }
  d-title h1 {
    font-size: 40px !important;
  }
  d-article {
    font-size: 15px !important;
  }
}
d-title h1,
d-title p {
  color: var(--global-text-color) !important;
}

d-byline {
  border-top-color: var(--global-divider-color) !important;
}
d-byline h3 {
  color: var(--global-text-color) !important;
}
d-byline a,
d-article d-byline a {
  color: var(--global-text-color) !important;
}
d-byline a:hover,
d-article d-byline a:hover {
  color: var(--global-hover-color) !important;
}

/* Article */
d-article {
  position: relative;
  border-top-color: var(--global-divider-color) !important;
}
d-article p,
d-article h1,
d-article h2,
d-article h3,
d-article h4,
d-article h5,
d-article h6,
d-article li,
d-article table {
  color: var(--global-text-color) !important;
}
d-article h1,
d-article h2,
d-article hr,
d-article table,
d-article table th,
d-article table td {
  border-bottom-color: var(--global-divider-color) !important;
}
d-article a {
  color: var(--global-theme-color) !important;
  border-bottom: none;
}
d-article a:hover {
  color: var(--global-hover-color) !important;
}
d-article b i {
  display: inline;
}
d-article blockquote {
  border-left: 2px solid var(--global-theme-color) !important;
}

/* Wide text column (grid columns 3 to -3), as on alexzhang13.github.io */
d-article p,
d-article h1,
d-article h2,
d-article h3,
d-article h4,
d-article figure,
d-article table,
d-article table tr,
d-article table tr th,
d-article table tr td,
d-article ul,
d-article ol,
d-article ul li,
d-article ol li,
d-article block,
d-article d-code,
d-article code,
d-article div,
d-article mjx-container[display="true"],
d-article .katex-display {
  grid-column-start: 3;
  grid-column-end: -3;
}
d-article mjx-container[display="true"],
d-article .katex-display {
  display: block;
  text-align: center;
  margin: 0.5em 0;
}

/* Figures are centred in the article column, narrower than the text.
   A caption is exactly as wide as its figure. */
d-article figure.l-page,
d-article figure.l-page + .caption {
  grid-column: 3 / -3;
  justify-self: center;
  box-sizing: border-box;
  width: 70%;
  /* never narrower than 600px, unless the column itself is */
  min-width: min(100%, 600px);
}
d-article figure.l-body {
  grid-column: text;
}
d-article figure {
  margin: 1.5rem 0 0;
}
d-article figure img {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  border-radius: 0.25rem;
  box-shadow: 0 2px 5px #00000029, 0 2px 10px #0000001f;
}
d-article .caption {
  font-size: 0.875rem;
  margin-top: 0.75rem;
  margin-bottom: 1.5rem;
  text-align: center;
  color: var(--global-text-color-light);
}

/* Animated figures (<post>/figures/anim/*.js): an inline SVG on the same white card
   as the image figures, with a Replay button in the top right corner. */
d-article figure.anim-fig {
  --anim-accent: #c0392b; /* the red of the plotted figures */
  --anim-ink: #333333;
  --anim-muted: #777777;
  position: relative;
  /* keep the card as tall as its content when the grid row is taller (the TOC spans rows) */
  align-self: start;
  padding: 10px 12px 6px;
  background: #ffffff;
  border-radius: 0.25rem;
  box-shadow: 0 2px 5px #00000029, 0 2px 10px #0000001f;
}
.anim-fig > svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
}
.anim-fig > svg text {
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  fill: var(--anim-ink);
}
.anim-fig .replay {
  position: absolute;
  top: 7px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--global-text-color-light);
  font: inherit;
  font-size: 11px;
  line-height: 1.4;
  cursor: pointer;
}
.anim-fig .replay:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--global-text-color);
}
.anim-fig .replay svg {
  width: 11px;
  height: 11px;
}
.anim-fig noscript img {
  box-shadow: none;
}
@media (scripting: none) {
  .anim-fig > svg,
  .anim-fig .replay {
    display: none;
  }
}

/* Plot frame and series */
.anim-fig .axis-line {
  fill: none;
  stroke: var(--anim-ink);
  stroke-width: 1;
}
.anim-fig > svg .title {
  font-size: 16px;
}
.anim-fig > svg .axis-label {
  fill: var(--anim-muted);
}
.anim-fig > svg .tick.on {
  font-weight: 700;
  fill: var(--anim-accent);
}
.anim-fig .series {
  fill: none;
  stroke: var(--anim-accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.anim-fig .dot {
  fill: var(--anim-accent);
}
.anim-fig .dot.on {
  stroke: #ffffff;
  stroke-width: 1.5;
}
/* Values and guides that fade in for the model being shown */
.anim-fig > svg .value {
  font-size: 13px;
  font-weight: 500;
  fill: var(--anim-accent);
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-linejoin: round;
  paint-order: stroke;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.anim-fig > svg .value.on {
  opacity: 1;
}
.anim-fig .guide {
  stroke: #bbbbbb;
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.anim-fig .guide.on {
  opacity: 1;
}
.anim-fig .hit {
  fill: transparent;
}

/* The bar above a figure: a grey track for the whole range, filled up to the current value */
.anim-fig .bar-track {
  fill: #e4e4e4;
}
.anim-fig .bar-fill {
  fill: var(--anim-accent);
}
.anim-fig .bar-tick {
  stroke: #b0b0b0;
  stroke-width: 1;
}
.anim-fig > svg .readout {
  font-size: 15px;
}
.anim-fig > svg .readout .num {
  font-weight: 700;
  fill: var(--anim-accent);
}
.anim-fig > svg .readout .note,
.anim-fig > svg .stop,
.anim-fig > svg .stop .note {
  fill: var(--anim-muted);
  font-weight: 400;
}
.anim-fig > svg .stop.on {
  font-weight: 700;
  fill: var(--anim-accent);
}

/* A needle moving away from the query on the bar, and curves against that distance */
.anim-fig .bar-fill.gap {
  fill-opacity: 0.35;
}
.anim-fig .needle {
  fill: var(--anim-accent);
  stroke: #ffffff;
  stroke-width: 2;
}
.anim-fig .query-pin {
  fill: var(--anim-ink);
}
.anim-fig > svg .query-label {
  font-size: 13px;
  font-weight: 500;
}
.anim-fig .beyond {
  fill: #e8e8e8; /* distances beyond the SWA window */
}
.anim-fig .window-line {
  stroke: #111111;
  stroke-width: 1;
  stroke-dasharray: 3 2;
}
.anim-fig .pulse {
  stroke: var(--anim-accent);
}
.anim-fig .series.thin {
  stroke-width: 1.8;
}

/* A line of text that narrates the animation; "hot" lines are in the accent colour */
.anim-fig > svg .message {
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.anim-fig > svg .message.on {
  opacity: 1;
  transition-delay: 0.15s; /* the old line leaves before the new one comes in */
}
.anim-fig > svg .message.hot,
.anim-fig > svg .message .hot {
  fill: var(--anim-accent);
}
.anim-fig > svg .message .quiet {
  fill: #8a8a8a;
}

/* Layer-by-head grids: one square per attention head */
.anim-fig .grid-open {
  fill: #ffffff;
}
.anim-fig .grid-band {
  fill: #d9d9d9;
}
.anim-fig .grid-lines {
  fill: none;
  stroke: rgba(0, 0, 0, 0.07);
  stroke-width: 0.5;
}
.anim-fig .grid-frame {
  fill: none;
  stroke: var(--anim-ink);
  stroke-width: 1;
}
.anim-fig .head {
  fill: var(--anim-accent);
}
.anim-fig .ripple {
  fill: none;
  stroke: var(--anim-accent);
  stroke-width: 1.5;
}
.anim-fig > svg .tally {
  font-size: 13px;
  fill: var(--anim-muted);
}
.anim-fig > svg .tally .num {
  font-weight: 700;
  fill: var(--anim-ink);
}
.anim-fig > svg .tally.hot .num {
  fill: var(--anim-accent);
}
.anim-fig > svg .legend text {
  font-size: 13px;
}
.anim-fig .swatch.grid-open {
  stroke: #999999;
  stroke-width: 1;
}

/* Bars per attention head, coloured by the kind of layer the head is in (lighter for random heads) */
.anim-fig .type-none {
  --bar: #4d4d4d;
}
.anim-fig .type-swa {
  --bar: #2b6cb0;
}
.anim-fig .type-nope {
  --bar: #d95f02;
}
.anim-fig .type-swa.random {
  --bar: #a9c4e0;
}
.anim-fig .type-alibi {
  --bar: #6a3d9a;
}
.anim-fig .type-alibi.random {
  --bar: #cab2d6;
}
.anim-fig .type-nope.random {
  --bar: #efc1a3;
}
.anim-fig .bar {
  fill: var(--bar);
}
.anim-fig .bar.ghost {
  fill-opacity: 0.22; /* the part of a bar that was lost */
}
.anim-fig .head-box {
  fill: var(--bar);
  stroke: var(--bar);
  stroke-width: 1;
}
.anim-fig .star {
  fill: #111111; /* a recall head before long-context extension */
}
.anim-fig .baseline {
  stroke: #111111;
  stroke-width: 1;
  stroke-dasharray: 3 2;
}
.anim-fig .bracket {
  fill: none;
  stroke: #999999;
  stroke-width: 1;
}
.anim-fig > svg .title.small {
  font-size: 13px;
}
.anim-fig > svg .tick.small {
  font-size: 11px;
}
.anim-fig > svg .group {
  font-size: 11.5px;
  fill: var(--anim-muted);
}
.anim-fig > svg .head-name {
  font-size: 11px;
}
.anim-fig > svg .head-name.on {
  font-weight: 700;
}
.anim-fig > svg .drop {
  font-size: 10px;
  font-weight: 600;
  fill: var(--anim-accent);
}

/* Distill-style table of contents in the left margin */
d-article d-contents {
  position: absolute;
  align-self: start;
  display: grid;
  grid-column: 1 / 3;
  grid-row: 1;
  grid-template-columns:
    minmax(8px, 1fr) [toc] auto
    minmax(8px, 1fr) [toc-line] 1px
    minmax(32px, 2fr);
  justify-self: end;
  width: calc(max(70%, 300px));
  margin: 0;
  padding-left: 2em;
  padding-right: 3em;
  border-right: 1px solid var(--global-divider-color);
  box-sizing: border-box;
}
d-article d-contents nav {
  grid-column: toc;
}
d-article d-contents nav h3 {
  margin-top: 0;
  margin-bottom: 1em;
}
d-article d-contents nav a {
  border-bottom: none !important;
  color: var(--global-text-color) !important;
}
d-article d-contents nav a:hover {
  border-bottom: 1px solid var(--global-text-color) !important;
  color: var(--global-text-color) !important;
}
d-article d-contents nav div {
  display: block;
  outline: none;
  margin-bottom: 0.8em;
  color: rgba(0, 0, 0, 0.8);
  font-weight: bold;
}
d-article d-contents nav ul {
  padding-left: 1em;
  margin-top: 0;
  margin-bottom: 6px;
  list-style-type: none;
}
d-article d-contents nav ul li {
  margin-bottom: 0.25em;
}

@media (max-width: 1024px) {
  d-article d-contents {
    position: static;
    display: block;
    grid-column: 2 / -2;
    grid-row: auto;
    justify-self: start;
    width: 100%;
    margin-bottom: 1em;
    padding: 0.5em 2em;
    border: 1px solid var(--global-divider-color);
  }

  d-article d-contents nav {
    grid-column: none;
  }
}

@media (max-width: 767px) {
  d-article figure.l-page,
  d-article figure.l-page + .caption {
    width: 100%;
  }
}

/* Inline code / details */
d-article code {
  background-color: var(--global-code-bg-color);
  border-radius: 4px;
  padding: 0.1em 0.3em;
  font-size: 0.92em;
}
d-article pre code {
  display: block;
  padding: 0.8em 1em;
  overflow-x: auto;
}
d-article details:not(.fold) {
  color: var(--global-text-color);
  background-color: var(--global-code-bg-color);
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  overflow: auto;
  max-width: 100%;
}
d-article details:not(.fold) summary {
  color: var(--global-theme-color);
}

/* BibTeX card in the Citation section (the look of alexzhang13.github.io's code cards) */
d-article .bibtex {
  grid-column: 3 / -3;
  border: 1px solid #d5dae2;
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  color: #1c232b;
  margin-bottom: 1em;
}
d-article .bibtex-bar {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  background: #f1f3f6;
  border-bottom: 1px solid #d5dae2;
}
d-article .bibtex-lang {
  font: 500 10.5px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5a6570;
}
d-article .bibtex-copy {
  margin-left: auto;
  font: 600 10.5px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5a6570;
  background: #ffffff;
  border: 1px solid #d5dae2;
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
}
d-article .bibtex-copy:hover {
  color: #1c232b;
  border-color: #5a6570;
}
d-article .bibtex-copy.ok {
  color: #15803d;
  border-color: #15803d;
  background: rgba(21, 128, 61, 0.08);
}
d-article .bibtex pre {
  margin: 0;
  padding: 12px 14px;
  background: none;
  font: 400 12.5px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  overflow-x: auto;
}
d-article .bibtex .tok-type { color: #7c3aed; }
d-article .bibtex .tok-key { color: #2563eb; }
d-article .bibtex .tok-str { color: #15803d; }
d-article .bibtex .tok-num { color: #b45309; }
d-article .bibtex .tok-punct { color: #5a6570; }

/* Folded sections (build.py's `collapsed`): the usual heading, with a caret, opens the section */
d-article details.fold {
  grid-column: 3 / -3;
}
d-article details.fold > summary {
  display: block;
  list-style: none;
  cursor: pointer;
}
d-article details.fold > summary::-webkit-details-marker {
  display: none;
}
/* the caret, a right-pointing triangle turned down when open, hangs in the margin so the
   heading stays in line with the text */
d-article details.fold > summary > h2::before,
d-article details.fold > summary > h3::before {
  content: "";
  display: inline-block;
  border-left: 0.34em solid;
  border-top: 0.24em solid transparent;
  border-bottom: 0.24em solid transparent;
  margin: 0 0.5em 0 -0.84em;
  vertical-align: 0.1em;
  color: var(--global-text-color-light);
  transition: transform 0.15s ease;
}
/* margins do not collapse across <details>: keep closed sections close together, with the
   usual space above a heading that follows an open section */
d-article details.fold > summary > h3 {
  margin-top: 20px;
}
d-article details.fold:not([open]) > summary > h3 {
  margin-bottom: 0;
}
d-article details.fold[open] + details.fold > summary > h3 {
  margin-top: 40px;
}
d-article details.fold[open] > summary > h2::before,
d-article details.fold[open] > summary > h3::before {
  transform: rotate(90deg);
}
d-article details.fold > summary:hover > h2::before,
d-article details.fold > summary:hover > h3::before {
  color: var(--global-text-color);
}

d-footnote {
  scroll-margin-top: 66px;
}

/* Sidenotes: footnotes shown in the right margin on wide screens (placed by sidenotes.js).
   Hidden unless the script finds enough room and adds .sidenotes-on to <body>. */
d-article > aside.sidenote {
  display: none;
  position: absolute;
  grid-column: auto;
  box-sizing: border-box;
  margin: 0;
  padding: 2px 5px 3px 20px;
  border-left: 2px solid transparent;
  border-radius: 2px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--global-text-color-light);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}
body.sidenotes-on d-article > aside.sidenote {
  display: block;
}
d-article > aside.sidenote .sidenote-num {
  position: absolute;
  top: 2px;
  left: 6px;
  font-size: 0.85em;
  font-weight: 600;
}
d-article > aside.sidenote.is-active {
  border-left-color: var(--global-text-color-light);
  background-color: rgba(130, 130, 130, 0.16);
}
/* The sidenotes replace the footnote list at the end of the post */
body.sidenotes-on d-footnote-list {
  display: none !important;
}

/* Appendix (footnotes, references) */
d-appendix {
  border-top-color: var(--global-divider-color) !important;
  color: var(--global-distill-app-color) !important;
}
d-appendix h3,
d-appendix li,
d-appendix span {
  color: var(--global-distill-app-color) !important;
}
d-appendix a,
d-appendix a.footnote-backlink {
  color: var(--global-distill-app-color) !important;
}
d-appendix a:hover,
d-appendix a.footnote-backlink:hover {
  color: var(--global-hover-color) !important;
}
d-citation-list .references {
  grid-column: text;
}
d-citation-list .references .title {
  font-weight: 500;
}
