/*
 * Stylesheet shared by the posts under /blogs/. Ported from the Nestor project
 * page (ma-lab-berkeley.github.io/Nestor): a centred text column, a sticky
 * table of contents on wide screens, figures slightly wider than the text.
 * The accent is the site's light blue (the homepage link colour).
 */

/* ---------------------------------------------------------------- tokens */
:root {
  --blue: #6c8ebf; /* the site's light blue */

  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --panel: #f0f2f5;
  --ink: #17171a;
  --ink-2: #3d3d44;
  --muted: #71717a;
  --line: #ececf0;
  --line-2: #dcdce2;
  --accent: var(--blue);
  --accent-ink: #4a6a9a; /* the blue, darkened for running text */
  --accent-mid: #a9bedb;
  --accent-soft: rgba(108, 142, 191, 0.12);
  --card: #ffffff;

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --col: 680px; /* the text column */
  --wide: 860px; /* breakout figures */
  --toc: 200px;
  --gutter: 16px;
  color-scheme: light;
}

/* ---------------------------------------------------------------- base */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}
h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}
h2 {
  font-size: 1.6rem;
  margin: 4.5rem 0 1.1rem;
}
h3 {
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  margin: 2.5rem 0 0.7rem;
}
p {
  margin: 0 0 1.1rem;
}
ul,
ol {
  padding-left: 1.25rem;
  margin: 0 0 1.1rem;
}
li {
  margin-bottom: 0.35rem;
}
li::marker {
  color: var(--muted);
}
a {
  color: var(--accent-ink);
  text-decoration: none;
}
a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
strong {
  color: var(--ink);
  font-weight: 600;
}
code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--panel);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
sup {
  font-size: 0.68em;
  line-height: 0;
  vertical-align: 0.55em;
}
::selection {
  background: var(--accent-soft);
  color: var(--ink);
}
hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.5rem 0;
}

/* ---------------------------------------------------------------- top nav */
.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 clamp(16px, 3vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}
.topnav__brand {
  flex: none;
  margin-right: 1.5rem;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.topnav__brand:hover {
  color: var(--ink);
  text-decoration: none;
}
.topnav__links {
  display: flex;
  gap: 1.75rem;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
.topnav__links::-webkit-scrollbar {
  display: none;
}
.topnav__links a {
  color: var(--muted);
  transition: color 0.15s;
}
.topnav__links a:hover {
  color: var(--ink);
  text-decoration: none;
}

/* ---------------------------------------------------------------- hero */
.hero {
  max-width: 820px;
  margin: 0 auto;
  padding: clamp(3.5rem, 8vw, 6rem) var(--gutter) 1.5rem;
  text-align: center;
}
.hero__meta {
  display: inline-block;
  margin: 0 0 1.4rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.hero__title {
  font-size: clamp(2rem, 4.6vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  max-width: 22ch;
  margin: 0 auto 1.25rem;
}
.hero__lede {
  font-size: 1.1rem;
  line-height: 1.5;
  color: var(--muted);
  max-width: 44ch;
  margin: 0 auto 1.75rem;
}
.hero__speaker {
  font-size: 0.95em;
  margin-right: 0.1em;
}
.hero__byline {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 0.3rem;
}
.hero__byline a {
  color: inherit;
}
.hero__affil {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}
.hero__affil .sep {
  color: var(--line-2);
  margin: 0 0.5rem;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0 1.15rem;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover {
  color: var(--ink);
  text-decoration: none;
  background: var(--bg-soft);
  border-color: var(--muted);
}
.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.btn--primary:hover {
  background: var(--ink-2);
  border-color: var(--ink-2);
  color: var(--bg);
}
.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.btn--sm {
  min-height: 28px;
  padding: 0 0.7rem;
  border-radius: 7px;
  font-size: 0.78rem;
}

/* ---------------------------------------------------------------- columns */
.column {
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, var(--col)) minmax(0, 1fr);
  column-gap: 48px;
  padding: 0 var(--gutter) 4rem;
}
.article {
  grid-column: 2;
  min-width: 0;
}
.toc {
  grid-column: 1;
  justify-self: end;
  width: var(--toc);
  margin-right: 48px; /* clear of the wide figures, which reach into the gap */
  position: sticky;
  z-index: 1;
  top: 96px;
  align-self: start;
  margin-top: 4.5rem;
  font-size: 0.82rem;
  line-height: 1.4;
  max-height: calc(100dvh - 120px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.toc__toggle {
  display: none;
}
.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc > ol {
  border-left: 1px solid var(--line);
}
.toc ol ol {
  margin-left: 0.75rem;
  font-size: 0.78rem;
}
.toc__item {
  margin: 0;
}
.toc__item > a {
  display: flex;
  gap: 0.45rem;
  padding: 0.35rem 0.25rem 0.35rem 0.7rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  transition: color 0.15s;
}
.toc__number {
  flex: none;
  font-variant-numeric: tabular-nums;
}
.toc__item a:hover {
  color: var(--ink);
  text-decoration: none;
}
.toc__item.is-active > a {
  border-left-color: var(--accent);
  color: var(--ink);
  font-weight: 500;
}
.toc__item > a:focus-visible,
.toc__toggle:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}
.heading-number {
  color: var(--muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 1180px) {
  .layout {
    display: block;
    max-width: calc(var(--col) + 2 * var(--gutter));
    margin: 0 auto;
  }
  .toc {
    position: static;
    width: 100%;
    max-height: none;
    margin: 2rem 0 0;
    overflow: visible;
  }
  .toc__toggle {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
  }
  .toc > ol {
    display: none;
  }
  .toc.is-open > ol {
    display: block;
    max-height: 60dvh;
    overflow-y: auto;
    margin-top: 0.75rem;
  }
  .toc.is-open .toc__toggle span {
    transform: rotate(180deg);
  }
}

/* ---------------------------------------------------------------- sections */
.section:first-child h2 {
  margin-top: 3.5rem;
}
.lead {
  font-size: 1.05rem;
}

/* a placeholder paragraph in a draft; delete once the section is written */
.draft {
  padding: 0.75rem 1rem;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  color: var(--muted);
  font-style: italic;
}

/* ---------------------------------------------------------------- hover notes */
/* the same device as the homepage: dotted underline, dark bubble on hover */
.hover-note {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  cursor: help;
}
.hover-bubble {
  position: fixed;
  z-index: 100;
  padding: 6px 14px;
  border-radius: 8px;
  color: #f5f5f5;
  background: #1a1a1a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, calc(-100% - 14px)) translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}
.hover-bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  margin-left: -4px;
  border-width: 4px;
  border-style: solid;
  border-color: #1a1a1a transparent transparent transparent;
}
.hover-bubble.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, calc(-100% - 14px));
}

/* ---------------------------------------------------------------- figures */
.figure {
  margin: 2rem 0 2.25rem;
}
.figure--column {
  width: 100%;
}
/* a wider element centred on the text column */
.breakout,
.figure--breakout {
  width: min(var(--wide), 100vw - 2 * var(--gutter));
  margin-left: 50%;
  transform: translateX(-50%);
}
.figure__surface {
  display: flex;
  justify-content: center;
}
.figure__surface img {
  display: block;
  width: 100%;
  height: auto;
}
figcaption {
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--muted);
  margin: 0.9rem auto 0;
  max-width: var(--col);
}
figcaption strong {
  color: var(--ink-2);
  font-weight: 600;
}

/* ---------------------------------------------------------------- callouts */
.callout {
  margin: 1.75rem 0;
  padding: 1.1rem 1.35rem 0.4rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.callout__head {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  margin-bottom: 0.6rem;
}
.callout__head strong {
  color: inherit;
}
.callout__head span {
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.callout p {
  margin-bottom: 0.75rem;
}

/* ---------------------------------------------------------------- code */
.code {
  margin: 1.25rem 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-soft);
}
.code__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.5rem 0.35rem 1.1rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}
.code pre {
  margin: 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--ink);
}
.code pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* ---------------------------------------------------------------- references */
.references {
  list-style: none;
  counter-reset: ref;
  margin: 0 0 1.1rem;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1.55;
}
.references li {
  position: relative;
  counter-increment: ref;
  margin-bottom: 0.6rem;
  padding: 0.15rem 0.4rem 0.15rem 2.4rem;
  margin-left: -0.4rem;
  border-radius: 8px;
}
.references li::before {
  content: "[" counter(ref) "]";
  position: absolute;
  left: 0.4rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.references li:target {
  background: var(--accent-soft);
}
.cite {
  font-size: 0.85em;
  font-weight: 500;
  color: var(--accent-ink);
  white-space: nowrap;
}
.cite:hover {
  text-decoration: none;
  color: var(--accent);
}
blockquote {
  margin: 1.5rem 0;
  padding: 0.2rem 0 0.2rem 1.25rem;
  border-left: 3px solid var(--accent-mid);
  color: var(--ink-2);
}
blockquote p {
  margin-bottom: 0.5rem;
}
blockquote footer {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------------------------------------------------------------- footer */
.footer {
  border-top: 1px solid var(--line);
  padding: 2rem var(--gutter) 3rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

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