/* Self-Direction project page.
   Palette comes from the method figure: navy ink, TRAIN blue, REUSE green, amber highlight.
   Bulma (loaded first) supplies the reset; everything visible is styled here. */

@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-roman.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #FBFAF7;
  --paper-2: #F4F2EC;
  --surface: #FFFFFF;
  --ink: #18212E;
  --ink-2: #3D4A5C;
  --muted: #667180;
  --rule: #E7E3DA;
  --rule-2: #EFECE6;
  --grid: #E8E6E0;

  --blue: #1685F8;
  --blue-ink: #0B63C5;
  --blue-tint: #EDF6FF;
  --green: #16A16A;
  --green-ink: #0B7A4F;
  --green-tint: #E7F8F0;
  --amber: #FFD478;
  --warn: #E8674B;
  --warn-tint: #FFF1EA;
  --deemph: #A9B2BE;

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Instrument Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --shadow-1: 0 1px 2px rgba(24, 33, 46, 0.05), 0 1px 1px rgba(24, 33, 46, 0.03);
  --shadow-2: 0 14px 34px -14px rgba(24, 33, 46, 0.22), 0 3px 8px rgba(24, 33, 46, 0.06);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ------------------------------------------------------------------ base */

html {
  background: var(--paper);
  scroll-behavior: smooth;
  scroll-padding-top: 76px;
}

body {
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-2);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--blue-ink);
  text-decoration: underline;
  text-decoration-color: rgba(11, 99, 197, 0.3);
  text-underline-offset: 3px;
  transition: color 0.2s, text-decoration-color 0.2s;
}

a:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

strong {
  color: var(--ink);
  font-weight: 650;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
  border-radius: 6px;
}

/* Bulma's reset gives figure/article display:block, which would override the hidden attribute */
[hidden] {
  display: none !important;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 28px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
  color: #fff;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.eyebrow-mark,
.brand-mark {
  width: 28px;
  height: 28px;
  flex: none;
}

/* ------------------------------------------------------------------ nav */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(251, 250, 247, 0.84);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.25s;
}

.site-nav.is-scrolled {
  border-bottom-color: var(--rule);
}

.nav-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  color: var(--ink);
}

.nav-links {
  display: flex;
  gap: 2px;
}

.nav-links a {
  padding: 8px 12px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}

.nav-links a:hover,
.nav-links a.is-active {
  color: var(--ink);
  background: rgba(24, 33, 46, 0.06);
}

/* ------------------------------------------------------------------ hero */

.hero-sd {
  position: relative;
  isolation: isolate;
  padding: 56px 0 60px;
  overflow: hidden;
}

.hero-wash {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(55% 45% at 10% 0%, rgba(22, 133, 248, 0.1), transparent 72%),
    radial-gradient(48% 42% at 92% 6%, rgba(22, 161, 106, 0.1), transparent 72%),
    radial-gradient(circle at 1px 1px, rgba(24, 33, 46, 0.11) 1px, transparent 1.5px) 0 0 / 22px 22px;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 45%, transparent 92%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 45%, transparent 92%);
}

.hero-sd .wrap {
  text-align: center;
}

.hero-sd .wrap > * {
  animation: rise 0.9s var(--ease) both;
}

.hero-sd .wrap > :nth-child(2) { animation-delay: 0.08s; }
.hero-sd .wrap > :nth-child(3) { animation-delay: 0.16s; }
.hero-sd .wrap > :nth-child(4) { animation-delay: 0.2s; }
.hero-sd .wrap > :nth-child(5) { animation-delay: 0.24s; }
.hero-sd .wrap > :nth-child(6) { animation-delay: 0.3s; }
.hero-sd .wrap > :nth-child(7) { animation-delay: 0.42s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.paper-title {
  max-width: 1000px;
  text-wrap: balance;
  margin: 4px auto 26px;
  font-family: var(--serif);
  color: var(--ink);
  letter-spacing: -0.02em;
}

.title-main,
.title-sub,
.tldr-statement,
.section-sd h2 {
  text-wrap: balance;
}

.phase p,
.xfer-proc,
.fit-card p {
  text-wrap: pretty;
}

/* Full-width paragraphs fill the column edge to edge */
.lede,
.abstract p,
.finding-text > p:last-child {
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  text-wrap: wrap;
}

.title-main {
  display: block;
  font-size: clamp(2.35rem, 5.7vw, 4.6rem);
  line-height: 1.02;
  font-weight: 500;
}

.title-main em {
  font-style: italic;
  padding: 0 0.04em;
  background: linear-gradient(transparent 64%, rgba(255, 212, 120, 0.8) 64%, rgba(255, 212, 120, 0.8) 90%, transparent 90%);
}

.title-sub {
  display: block;
  margin-top: 14px;
  font-size: clamp(1.25rem, 2.4vw, 1.95rem);
  line-height: 1.22;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink-2);
}

.authors {
  max-width: 880px;
  margin: 0 auto 8px;
  font-size: 17.5px;
  font-weight: 500;
  line-height: 1.85;
  color: var(--ink);
  text-wrap: balance;
}

.author {
  display: inline-block;
  margin: 0 9px;
  white-space: nowrap;
}

.authors a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: rgba(24, 33, 46, 0.22);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.authors a:hover {
  color: var(--blue-ink);
  text-decoration-color: currentColor;
}

.authors sup,
.affiliations sup,
.footnote-line sup {
  margin-left: 1px;
  font-size: 0.66em;
  font-weight: 600;
  color: var(--muted);
}

.affiliations {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 22px;
  margin: 0;
  font-size: 15.5px;
  color: var(--ink-2);
}

.footnote-line {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 26px 0 40px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: transform 0.2s var(--ease), box-shadow 0.2s, background 0.2s;
}

.pill-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pill-btn:hover {
  color: #fff;
  background: #0E151F;
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

.pill-btn.is-soon,
.pill-btn.is-soon:hover {
  background: var(--surface);
  border-color: var(--rule);
  color: var(--ink-2);
  box-shadow: none;
  transform: none;
  cursor: default;
}

.soon {
  padding: 2px 7px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-figure {
  max-width: 1080px;
  margin: 0 auto;
}

.anim-frame {
  position: relative;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border: 1px solid rgba(24, 33, 46, 0.08);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 34px 70px -36px rgba(24, 33, 46, 0.32), 0 10px 24px -12px rgba(24, 33, 46, 0.12);
}

.anim-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* ------------------------------------------------------------------ TL;DR band */

.band {
  padding: 60px 0 56px;
  background: var(--surface);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.fork-divider {
  display: block;
  width: 220px;
  height: 22px;
  margin: 0 auto 26px;
}

.tldr-statement {
  margin: 0 auto 40px;
  text-align: center;
  font-family: var(--serif);
  font-size: clamp(1.45rem, 2.6vw, 2.05rem);
  line-height: 1.32;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.tldr-statement strong {
  font-weight: 600;
}

.tldr-statement strong,
.abstract strong {
  white-space: nowrap;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--paper);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 22px 20px;
  border-left: 1px solid var(--rule);
}

.stat:first-child {
  border-left: 0;
}

.stat-label {
  min-height: 2.7em;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--muted);
}

.stat-value {
  font-family: var(--sans);
  font-size: clamp(2rem, 3.4vw, 2.75rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.stat-delta {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--ink-2);
}

.stat-delta.is-good {
  color: var(--green-ink);
}

.stat-delta svg {
  flex: none;
  width: 12px;
  height: 12px;
  margin-top: 3px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fineprint {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ sections */

.section-sd {
  padding: 96px 0;
}

.section-sd.is-tinted {
  background: var(--paper-2);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.section-head {
  margin-bottom: 44px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--rule);
}

.section-head h2 {
  margin-bottom: 16px !important;
}

.section-head .lede {
  margin: 0;
  font-size: 19px;
  line-height: 1.65;
}

.section-sd h2 {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: clamp(1.9rem, 3.4vw, 2.75rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.lede {
  margin: 0;
  font-size: 18.5px;
  line-height: 1.6;
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ problem */

.encounters {
  display: grid;
  grid-template-columns: minmax(0, 380px) 140px minmax(0, 1fr);
  align-items: center;
}

.enc-card {
  padding: 22px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.enc-kicker {
  display: block;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.enc-first {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.enc-icon {
  width: 64px;
  height: 64px;
  margin: 2px 0 8px;
}

.enc-first strong {
  font-size: 18px;
}

.enc-first span:last-child {
  font-size: 15px;
  color: var(--muted);
}

.enc-split {
  width: 120px;
  height: 200px;
}

.enc-future {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.enc-future .enc-kicker {
  margin-bottom: 0;
}

.enc-bad,
.enc-good {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
}

.enc-bad div,
.enc-good div {
  display: flex;
  flex-direction: column;
}

.enc-bad strong,
.enc-good strong {
  font-size: 17px;
}

.enc-bad span,
.enc-good span {
  font-size: 15px;
  color: var(--ink-2);
}

.enc-good {
  border-color: rgba(22, 161, 106, 0.35);
  background: linear-gradient(0deg, #F2FBF6, #fff);
}

.enc-badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
}

.enc-badge svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.enc-badge.is-bad { background: var(--warn-tint); }
.enc-badge.is-bad svg { stroke: #C4472C; }
.enc-badge.is-good { background: var(--green-tint); }
.enc-badge.is-good svg { stroke: var(--green-ink); }

/* problem: anecdote + why the usual fixes fall short */

.anecdote {
  margin: 0 0 48px;
  padding: 26px 28px 22px;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.anecdote-head {
  margin-bottom: 20px;
}

.anecdote-kicker,
.step-label,
.gap-where {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.anecdote-head q {
  display: block;
  margin-top: 8px;
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.4;
  color: var(--ink);
  quotes: "\201C" "\201D";
}

.anecdote-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.anecdote-step {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--paper);
  border-top: 3px solid var(--rule);
}

.anecdote-step p {
  flex: 1;
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
}

.anecdote-step.is-fail { border-top-color: var(--warn); }
.anecdote-step.is-reflect { border-top-color: var(--blue); background: var(--blue-tint); }
.anecdote-step.is-pass { border-top-color: var(--green); background: var(--green-tint); }

.step-answer {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.is-fail .step-answer b { color: #C4472C; }
.is-pass .step-answer b { color: var(--green-ink); }

.anecdote-note {
  margin: 16px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

.gap-title {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
  color: var(--ink);
}

.gap-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 52px;
}

.gap-card {
  padding: 18px 20px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
}

.gap-card .gap-where {
  margin-bottom: 8px;
  color: var(--ink-2);
}

.gap-card p {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-2);
}

@media (max-width: 900px) {
  .anecdote-steps, .gap-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .anecdote { padding: 20px 16px 18px; }
  .anecdote-head q { font-size: 18px; }
}

/* ------------------------------------------------------------------ abstract */

.abstract p {
  margin: 0 0 1.1em;
  font-family: var(--serif);
  font-size: 19.5px;
  line-height: 1.7;
  color: var(--ink);
}

.abstract p:last-child {
  margin-bottom: 0;
}

.abstract {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 64px;
}

.abstract p {
  margin-bottom: 0 !important;
}

/* ------------------------------------------------------------------ method */

.phases {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.phase {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px 20px 20px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--surface);
}

.phase::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 20px;
  right: 20px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--ink);
}

.phase.is-train::before { background: var(--blue); }
.phase.is-reuse::before { background: linear-gradient(90deg, var(--blue), var(--green)); }

.phase-num {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.phase h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
}

.phase p {
  flex: 1;
  margin: 0;
  font-size: 15.5px;
  line-height: 1.6;
}

.phase-detail {
  padding: 7px 9px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ results */

.finding {
  padding: 56px 0 64px;
  border-top: 1px solid var(--rule);
}

.section-head + .finding {
  padding-top: 4px;
  border-top: 0;
}

.finding-head {
  margin-bottom: 24px;
}

.finding-num {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.finding-num span {
  padding: 2px 9px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.finding-text h3 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: clamp(1.6rem, 2.6vw, 2.05rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.012em;
  color: var(--ink);
  text-wrap: balance;
}

.finding-text > p:last-child {
  margin: 0;
  font-size: 17px;
  line-height: 1.65;
}

.finding-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 24px 0 0;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
}

.finding-stats > div {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  gap: 6px;
  padding: 18px 22px 16px;
  border-left: 1px solid var(--rule);
}

.finding-stats > div:first-child {
  border-left: 0;
}

.finding-stats dd {
  margin: 0;
  font-family: var(--sans);
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: var(--ink);
}

.finding-stats dt {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-2);
}

.finding-stats dt span {
  display: block;
  margin-top: 1px;
  color: var(--muted);
}

/* figure panels: the paper's figures and tables behind tabs */

.figpanel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.figtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule-2);
  background: var(--paper);
}

html:not(.js) .figtabs {
  display: none;
}

.figtabs [role="tab"] {
  padding: 7px 15px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.figtabs [role="tab"]:hover {
  color: var(--ink);
  background: rgba(24, 33, 46, 0.06);
}

.figtabs [role="tab"][aria-selected="true"] {
  color: #fff;
  background: var(--ink);
}

.figstage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px 32px 24px;
}

.figitem {
  margin: 0;
}

.figitem + .figitem {
  margin-top: 40px;
}

html.js .figitem + .figitem {
  margin-top: 0;
}

.figimg {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(300px, 34vw, 460px);
  cursor: zoom-in;
}

.figimg img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.figimg::after {
  content: "Full size";
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  opacity: 0;
  transition: opacity 0.2s;
}

.figimg:hover::after,
.figimg:focus-visible::after {
  opacity: 1;
}

.figitem figcaption {
  max-width: 820px;
  margin: 20px auto 0;
  font-size: 14.5px;
  line-height: 1.6;
  text-align: center;
  text-wrap: pretty;
  color: var(--ink-2);
}

.figitem figcaption b {
  font-weight: 650;
  color: var(--ink);
}

.figitem.is-table figcaption {
  margin-top: 18px;
}

/* tables reproduced from the paper */

.table-scroll {
  position: relative; /* keeps absolutely positioned helpers (e.g. .visually-hidden) inside the scroller */
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  background: var(--surface);
}

.data-table th,
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule-2);
  text-align: left;
  vertical-align: middle;
  color: var(--ink-2);
}

.data-table thead th {
  border-bottom: 1px solid var(--rule);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.35;
  vertical-align: bottom;
  color: var(--ink-2);
}

.data-table tbody th {
  font-weight: 600;
  color: var(--ink);
}

.data-table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.data-table .delta {
  font-weight: 650;
  color: var(--green-ink);
}

.paper-table {
  min-width: 620px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.paper-table thead th.group {
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

.paper-table thead tr:first-child th[rowspan] {
  vertical-align: bottom;
}

.paper-table tbody + tbody {
  border-top: 1px solid var(--rule);
}

.paper-table tbody tr:last-child th,
.paper-table tbody tr:last-child td {
  border-bottom: 0;
}

.paper-table tbody.is-total {
  background: var(--paper);
}

.paper-table tbody.is-total th,
.paper-table tbody.is-total td {
  font-weight: 650;
  color: var(--ink);
}

.paper-table tbody.is-total .delta {
  color: var(--green-ink);
}

.cell-sub {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

.check {
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: middle;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%230B7A4F' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ------------------------------------------------------------------ skills */

.group-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin: 0 0 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
}

.group-title span {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.xfer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 52px;
}

.xfer-grid.is-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 0;
}

.xfer-grid.is-three .xfer-route {
  grid-template-columns: 1fr;
  gap: 4px;
}

.xfer-grid.is-three .xfer-arrow {
  justify-self: start;
  margin-left: 14px;
  transform: rotate(90deg);
}

.xfer {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--surface);
}

.xfer-route {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
}

.xfer-node {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
}

.xfer-node small {
  display: block;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.xfer-node.is-source { background: var(--blue-tint); }
.xfer-node.is-target { background: var(--green-tint); }

.xfer-arrow {
  align-self: center;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.xfer-proc {
  flex: 1;
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-2);
}

.xfer-outcome {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--rule-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--green-ink);
}

/* ------------------------------------------------------------------ context */

.fit-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.fit-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 20px 20px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--surface);
}

.fit-where {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.fit-card h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.fit-card p {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
}

.fit-card > p:not(.fit-score) {
  flex: 1;
}

.fit-score {
  margin-top: 6px !important;
  padding-top: 12px;
  border-top: 1px solid var(--rule-2);
  font-size: 13.5px !important;
  color: var(--muted);
}

.fit-score b {
  margin-right: 6px;
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.fit-card.is-ours {
  border-color: var(--ink);
  background: var(--ink);
}

.fit-card.is-ours h3,
.fit-card.is-ours .fit-score b { color: #fff; }
.fit-card.is-ours p { color: #C9D1DC; }
.fit-card.is-ours .fit-where { color: #8FD3B4; }
.fit-card.is-ours .fit-score { border-top-color: rgba(255, 255, 255, 0.14); color: #AEB8C6; }

/* sections after the results share the page's left edge, with a reading-width column */

/* ------------------------------------------------------------------ BibTeX */

.bibtex-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.bibtex-header h2 {
  margin: 0;
}

.copy-bibtex-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.copy-bibtex-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.copy-bibtex-btn.copied {
  background: var(--green-ink);
}

#bibtex-code {
  margin: 0;
  padding: 22px 24px;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#bibtex-code code {
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
}

/* ------------------------------------------------------------------ footer + utilities */

.footer-sd {
  padding: 48px 0 64px;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.footer-sd p {
  margin: 12px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

.scroll-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s var(--ease), visibility 0.25s;
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.scroll-to-top svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* scroll reveal (only when JS runs; see index.js) */
html.js .reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease);
}

html.js .reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* ------------------------------------------------------------------ responsive */

@media (max-width: 980px) {
  .phases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .xfer-grid.is-three { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .abstract { grid-template-columns: 1fr; row-gap: 1.1em; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--rule); }
}

@media (max-width: 760px) {
  .encounters { grid-template-columns: 1fr; gap: 18px; }
  .enc-split { display: none; }
  .enc-first { max-width: none; }
  .xfer-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .wrap, .nav-inner { padding-left: 18px; padding-right: 18px; }
  .hero-sd { padding: 36px 0 44px; }
  .anim-frame { aspect-ratio: 4 / 5; border-radius: 16px; }
  .section-sd { padding: 68px 0; }
  .section-head { margin-bottom: 30px; }
  .lede { font-size: 17px; }
  .abstract p { font-size: 18px; }
  .nav-links a { padding: 7px 8px; font-size: 11px; letter-spacing: 0.06em; }
  .brand span { display: none; }
  .finding { padding: 44px 0 48px; }
  .finding-text > p:last-child { font-size: 16px; }
  .figtabs { flex-wrap: nowrap; overflow-x: auto; }
  .figtabs [role="tab"] { flex: none; }
  .figstage { padding: 18px 14px 16px; }
  .figimg { height: auto; }
  .figimg::after { opacity: 1; }
  .figitem figcaption { font-size: 14px; text-align: left; }
}

@media (max-width: 520px) {
  .kpi-row { grid-template-columns: 1fr; }
  .stat-label { min-height: 0; }
  .stat { border-left: 0; }
  .stat + .stat { border-top: 1px solid var(--rule); }
  .phases, .fit-grid { grid-template-columns: 1fr; }
  .pill-btn { padding: 9px 14px; font-size: 14px; }
  .finding-stats { grid-template-columns: 1fr; }
  .finding-stats > div {
    flex-direction: row-reverse;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    padding: 12px 14px;
    border-left: 0;
    border-top: 1px solid var(--rule);
  }
  .finding-stats > div:first-child { border-top: 0; }
  .finding-stats dd { min-width: 104px; font-size: 1.35rem; }
  .xfer-route { grid-template-columns: 1fr; }
  .xfer-arrow { justify-self: center; transform: rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hero-sd .wrap > * { animation: none; }
  html.js .reveal { opacity: 1; transform: none; transition: none; }
}

@media print {
  .site-nav, .scroll-to-top, .figtabs { display: none; }
  html.js .reveal { opacity: 1; transform: none; }
  html.js .figitem[hidden] { display: block !important; }
}

/* ------------------------------------------------------------------ implementation page */

.impl-hero {
  padding: 64px 0 56px;
}

.impl-title {
  margin: 4px 0 18px;
  font-family: var(--serif);
  font-size: clamp(2.3rem, 5vw, 3.8rem);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.impl-lede {
  margin: 0 0 26px;
  font-size: 19px;
  line-height: 1.65;
  color: var(--ink-2);
  text-align: justify;
  hyphens: auto;
}

.stack {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stack li {
  padding: 8px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  color: var(--ink-2);
}

.stack b {
  font-weight: 650;
  color: var(--ink);
}

.code-card {
  margin: 0;
  overflow: hidden;
  border: 1px solid #1E2938;
  border-radius: 16px;
  background: #121A26;
  box-shadow: var(--shadow-2);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #223044;
  background: #172131;
}

.code-file {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  color: #DCE6F2;
}

.code-tag {
  padding: 3px 9px;
  border: 1px solid #2E3E55;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8FA3BC;
}

pre.code {
  margin: 0;
  padding: 18px 20px 20px;
  overflow-x: auto;
  background: transparent;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  color: #D6E1EE;
  white-space: pre;
}

pre.code code {
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
}

.tok-com { color: #7D8FA7; font-style: italic; }
.tok-str { color: #9BD8B2; }
.tok-kw  { color: #8AB8FF; font-weight: 700; }
.tok-num { color: #F5C978; }
.tok-fn  { color: #F2F5F9; font-weight: 700; }

.impl-step {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  padding: 44px 0;
  border-top: 1px solid var(--rule);
}

.section-head + .impl-step {
  padding-top: 4px;
  border-top: 0;
}

.impl-step-text h3 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.15;
  color: var(--ink);
}

.impl-step-text p {
  margin: 0 0 12px;
  text-align: justify;
  hyphens: auto;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-2);
}

.impl-note {
  padding: 10px 14px;
  border-left: 3px solid var(--blue);
  border-radius: 0 10px 10px 0;
  background: var(--blue-tint);
  font-size: 14px !important;
}

.impl-note code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.7);
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--ink);
}

.settings-table td:last-child {
  color: var(--ink);
}

@media (max-width: 900px) {
}

@media (max-width: 640px) {
  .impl-hero { padding: 40px 0 36px; }
  pre.code { font-size: 12px; padding: 14px; }
}

/* back-to-project-page button (implementation page) */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px 8px 11px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  transition: background 0.2s, transform 0.2s var(--ease);
}

.back-btn:hover {
  color: #fff;
  background: #0E151F;
  transform: translateX(-2px);
}

.back-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-btn.back-btn-hero {
  display: flex;
  width: fit-content;
  margin-bottom: 26px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
}

.back-btn.back-btn-hero:hover {
  color: var(--ink);
  background: var(--paper-2);
}

.footer-sd .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

@media (max-width: 640px) {
  .site-nav .back-btn span { display: none; }
  .site-nav .back-btn { padding: 8px; }
}
