/* NanoSense site system: journal article world.
   Paper ground, ink-green fields, highlighter for cited source spans,
   proof-red for the single primary action. No framework, no CDN. */

:root {
  --paper: #f6f8f5;
  --paper-2: #ebf0ea;
  --rule: #c3d0c6;
  --ink: #0c1f19;
  --ink-2: #2d4037;
  --ink-3: #4b5f56;
  --field: #0b2f25;
  --field-2: #134034;
  --field-rule: #2b5a4b;
  --on-field: #f2f6f2;
  --on-field-2: #b9cec4;
  --mark: #ffe74a;
  --mark-soft: #fff4a8;
  --red: #c8321a;
  --red-deep: #a82813;
  --focus: #c8321a;

  --serif: "Literata", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --margin-col: 11.5rem;
  --gutter: clamp(1.5rem, 3.2vw, 3rem);
  --wrap: 82rem;
  --measure: 66ch;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 5rem;
  scrollbar-color: var(--field) var(--paper-2);
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--red);
}

::selection { background: var(--mark); color: var(--ink); }

img, svg { display: block; max-width: 100%; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; text-wrap: balance; }
p, ul, ol, dl, figure, table { margin: 0; }
p { text-wrap: pretty; }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 1px;
}
.on-field :focus-visible,
.masthead :focus-visible,
.site-footer :focus-visible { outline-color: var(--on-field); }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: 0.7rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font: 600 0.9375rem var(--sans);
}
.skip-link:focus { top: 1rem; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.wrap {
  width: min(100% - 2 * var(--gutter), var(--wrap));
  margin-inline: auto;
}

/* ---------- Masthead ---------- */

.masthead {
  background: var(--field);
  color: var(--on-field);
  font-family: var(--sans);
  position: sticky;
  top: 0;
  z-index: 50;
}
.masthead .wrap {
  display: flex;
  align-items: center;
  gap: 2rem;
  min-height: 4.25rem;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.1875rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.wordmark img { width: 1.55rem; height: auto; }
.nav { display: flex; align-items: center; gap: 1.6rem; margin-left: auto; }
.nav a {
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  padding-top: 0.7rem; padding-bottom: 0.7rem;
  border-bottom: 2px solid transparent;
}
.nav a:hover { border-bottom-color: var(--on-field-2); }
.nav a[aria-current="page"] { border-bottom-color: var(--on-field); }
.nav .btn { margin-left: 0.4rem; padding-top: 0.6rem; padding-bottom: 0.6rem; border-bottom: 0; }

.menu { display: none; margin-left: auto; }
.menu summary {
  list-style: none;
  cursor: pointer;
  font: 600 0.9375rem var(--sans);
  padding: 0.7rem 0.2rem;
}
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { color: var(--on-field-2); }
.menu-panel {
  position: absolute;
  left: 0; right: 0; top: 100%;
  background: var(--field);
  border-top: 1px solid var(--field-rule);
  padding: 1rem var(--gutter) 1.5rem;
  display: grid;
  gap: 0.2rem;
}
.menu-panel a { padding: 0.8rem 0; text-decoration: none; font-weight: 500; border-bottom: 1px solid var(--field-rule); }
.menu-panel .btn { margin-top: 1rem; text-align: center; justify-content: center; border-bottom: 0; }

@media (max-width: 62rem) {
  .nav { display: none; }
  .menu { display: block; }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.35rem;
  background: var(--red);
  color: #fff;
  border: 1px solid var(--red-deep);
  border-radius: 2px;
  font: 600 1rem/1.2 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.18s var(--ease-out), transform 0.18s var(--ease-out);
}
.btn:hover { background: var(--red-deep); }
.btn:active { transform: translateY(1px); }
.btn::after {
  content: "";
  width: 0.95em; height: 0.95em;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h11M9 3.5 13.5 8 9 12.5' fill='none' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8h11M9 3.5 13.5 8 9 12.5' fill='none' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") center / contain no-repeat;
}
.btn.no-arrow::after { display: none; }

.text-link {
  font: 600 1rem var(--sans);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.3em;
  text-decoration-color: var(--red);
  padding-top: 0.5rem; padding-bottom: 0.5rem;
}
.on-field .text-link { text-decoration-color: var(--on-field); }

/* ---------- Title block ---------- */

.title-block { padding-block: clamp(2.5rem, 5vw, 4.5rem) clamp(1.5rem, 3vw, 2.5rem); }
.article {
  display: grid;
  grid-template-columns: var(--margin-col) minmax(0, 1fr);
  column-gap: var(--gutter);
}
.article.has-aside { grid-template-columns: var(--margin-col) minmax(0, 1fr) minmax(16rem, 21rem); }
.article > .span-all { grid-column: 2 / -1; }

.display {
  font-size: clamp(2.9rem, 6.6vw, 6rem);
  line-height: 1.02;
  font-weight: 500;
  letter-spacing: -0.028em;
  max-width: 14ch;
  padding-bottom: 0.1em;
}
.display.wide { max-width: 18ch; }
.title-page .display { font-size: clamp(2.4rem, 5vw, 4.25rem); max-width: 20ch; }

.deck {
  font-size: clamp(1.2rem, 1.7vw, 1.45rem);
  line-height: 1.5;
  font-style: italic;
  color: var(--ink-2);
  max-width: 46ch;
  margin-top: clamp(1.75rem, 3vw, 2.5rem);
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1.2rem 1.8rem; margin-top: 1.6rem; }

.meta {
  font: 500 0.875rem/1.45 var(--sans);
  color: var(--ink-3);
  display: grid;
  gap: 0.9rem;
  align-content: start;
  padding-top: 0.6rem;
}
.meta dt { font-weight: 700; color: var(--ink); }
.meta dd { margin: 0; }

/* ---------- Figure: cited answer ---------- */

.figure-row { padding-top: 2rem; padding-bottom: 4rem; border-top: 1px solid var(--ink); }
.fig-label { font: 500 0.875rem/1.45 var(--sans); color: var(--ink-3); padding-top: 0.2rem; }
.fig-label strong { color: var(--ink); display: block; }

.qa-question {
  font: 600 1.0625rem/1.4 var(--sans);
  padding: 0 0 1rem;
  margin-bottom: 1.1rem;
  border-bottom: 1px solid var(--rule);
}
.qa-question span { font-weight: 500; color: var(--ink-3); display: block; font-size: 0.875rem; margin-bottom: 0.25rem; }
.qa-answer { font-size: 1.1875rem; line-height: 1.7; max-width: 52ch; }
.qa-answer p + p { margin-top: 0.9rem; }
.qa-limit { font-style: italic; color: var(--ink-2); }

.hl {
  background: linear-gradient(var(--mark), var(--mark)) no-repeat 0 100% / 0% 0.34em;
  transition: background-size 0.7s var(--ease-out);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: 0.05em 0.1em;
  margin: 0 -0.1em;
}
.is-seen .hl { background-size: 100% 0.34em; }
.is-seen .hl.is-active { background-size: 100% 100%; box-shadow: 0 0 0 1px var(--ink); }
.no-js .hl { background-size: 100% 0.34em; }

.cite {
  font: 700 0.72em/1 var(--sans);
  vertical-align: super;
  color: var(--red);
  text-decoration: none;
  padding: 0.18em 0.28em;
  margin-left: 0.05em;
  border-radius: 2px;
  cursor: pointer;
}
.cite:hover, .cite.is-active { background: var(--ink); color: var(--mark); }

.sources { display: grid; gap: 1.1rem; align-content: start; }
.source {
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  padding-top: 0.7rem;
  border-top: 1px solid var(--ink);
  transition: opacity 0.2s;
}
.source-meta { font-weight: 700; display: flex; gap: 0.5rem; }
.source-meta .n { color: var(--red); }
.source-body { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sources.has-active .source:not(.is-active) { opacity: 0.55; }

.syn-note {
  margin-top: 1.4rem;
  font: 500 0.875rem/1.5 var(--sans);
  color: var(--ink-3);
  max-width: 52ch;
}

/* ---------- Sections (heading in the margin) ---------- */

.section { padding-top: 4.5rem; padding-bottom: 4.5rem; border-top: 1px solid var(--ink); }
.section .article > h2,
.section-title {
  font-size: 1.3rem;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.005em;
  position: sticky;
  top: 5.5rem;
  align-self: start;
  padding-right: 0.5rem;
}
.section-body > * + * { margin-top: 1.2rem; }
.section-body h3 { font: 700 1.0625rem/1.3 var(--sans); margin-top: 2.2rem; }
.section-body h3:first-child { margin-top: 0; }
.prose { max-width: var(--measure); }
.prose p + p { margin-top: 1rem; }
.lead { font-size: 1.3rem; line-height: 1.55; max-width: 52ch; }

.abstract { border: 1px solid var(--ink); max-width: 56rem; }
.abstract > div {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.1rem 1.4rem;
  border-top: 1px solid var(--rule);
}
.abstract > div:first-child { border-top: 0; }
.abstract dt { font: 700 0.9375rem/1.5 var(--sans); }
.abstract dd { margin: 0; }

.on-field {
  background: var(--field);
  color: var(--on-field);
}
.on-field .section { border-top-color: var(--field-rule); }
.on-field a { text-decoration-color: color-mix(in srgb, var(--on-field) 55%, transparent); }
.on-field .cite { background: var(--on-field); color: var(--field); font-size: 0.78em; padding: 0.22em 0.4em; }
.on-field .cite:hover { background: var(--field-2); color: var(--on-field); outline: 1px solid var(--on-field); }
.on-field .muted { color: var(--on-field-2); }

.statements { display: grid; gap: 0; max-width: 56rem; }
.statements > div {
  display: grid;
  grid-template-columns: 12rem minmax(0, 1fr);
  gap: 1.5rem;
  padding-top: 1.3rem; padding-bottom: 1.3rem;
  border-top: 1px solid var(--field-rule);
}
.statements > div:first-child { border-top: 0; padding-top: 0; }
.statements dt { font: 700 1rem/1.5 var(--sans); color: var(--on-field); }
.statements dd { margin: 0; max-width: 56ch; }

/* ---------- Sequence ---------- */

.sequence { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; counter-reset: step; }
.sequence li {
  counter-increment: step;
  padding: 1.6rem 1.4rem 0.4rem 0;
  border-top: 2px solid var(--ink);
  position: relative;
}
.sequence li::before {
  content: counter(step);
  position: absolute;
  top: -0.9rem;
  left: 0;
  background: var(--paper);
  padding-right: 0.7rem;
  font: 700 1.5rem/1 var(--serif);
  color: var(--red);
}
.sequence strong { display: block; font: 700 1.0625rem var(--sans); margin-bottom: 0.3rem; }
.sequence span { font-size: 0.975rem; color: var(--ink-2); display: block; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9625rem;
  font-variant-numeric: tabular-nums;
  min-width: 36rem;
}
table.data caption {
  text-align: left;
  font: 500 0.9375rem/1.5 var(--sans);
  color: var(--ink-3);
  padding-bottom: 0.7rem;
}
table.data caption strong { color: var(--ink); }
table.data th, table.data td { text-align: left; padding: 0.8rem 1rem 0.8rem 0; vertical-align: top; border-bottom: 1px solid var(--rule); }
table.data thead th { border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-weight: 700; }
table.data tbody th { font-weight: 600; }
table.data tfoot td { border-bottom: 2px solid var(--ink); color: var(--ink-3); }
.price { font: 500 1.9rem/1.1 var(--serif); letter-spacing: -0.02em; display: block; }
.price small { font: 500 0.9rem var(--sans); color: var(--ink-3); letter-spacing: 0; }

/* ---------- References ---------- */

.refs { list-style: none; padding: 0; counter-reset: ref; max-width: 52rem; }
.refs li {
  counter-increment: ref;
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  padding-top: 0.7rem; padding-bottom: 0.7rem;
  border-top: 1px solid var(--field-rule);
  font-family: var(--sans);
  font-size: 1rem;
}
.refs li::before { content: counter(ref) "."; color: var(--on-field-2); font-weight: 700; }
.refs li span { display: block; color: var(--on-field-2); font-size: 0.9rem; }

/* ---------- Faq / details ---------- */

.faq details { border-top: 1px solid var(--rule); padding-top: 0.2rem; padding-bottom: 0.2rem; }
.faq details:last-child { border-bottom: 1px solid var(--rule); }
.faq summary { cursor: pointer; font: 600 1.0625rem/1.4 var(--sans); padding-top: 1rem; padding-bottom: 1rem; list-style: none; display: flex; justify-content: space-between; gap: 1rem; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-weight: 500; color: var(--red); }
.faq details[open] summary::after { content: "\2212"; }
.faq details p { padding-bottom: 1.1rem; max-width: 60ch; }

/* ---------- Code (docs only) ---------- */

pre, code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; }
.section-body { min-width: 0; }
pre { max-width: 100%; background: var(--paper-2); border: 1px solid var(--rule); padding: 1rem 1.2rem; overflow-x: auto; line-height: 1.55; }
:not(pre) > code { background: var(--paper-2); padding: 0.08em 0.35em; border-radius: 2px; }

/* ---------- Footer ---------- */

.site-footer { background: var(--field); color: var(--on-field); font-family: var(--sans); padding-block: 3.5rem 2.5rem; }
.site-footer .cols { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)); gap: 2.5rem; }
.site-footer h2 { font: 700 0.9375rem var(--sans); color: var(--on-field-2); margin-bottom: 0.8rem; }
.site-footer ul { list-style: none; padding: 0; display: grid; gap: 0.2rem; }
.site-footer a { text-decoration: none; display: inline-block; padding-top: 0.3rem; padding-bottom: 0.3rem; font-size: 0.9625rem; }
.site-footer a:hover { text-decoration: underline; }
.site-footer .fine { margin-top: 3rem; padding-top: 1.4rem; border-top: 1px solid var(--field-rule); font-size: 0.875rem; color: var(--on-field-2); display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; justify-content: space-between; }
.site-footer .about { color: var(--on-field-2); max-width: 32ch; margin-top: 0.9rem; font-size: 0.9625rem; line-height: 1.55; }

/* ---------- Responsive ---------- */

@media (max-width: 70rem) {
  .article.has-aside { grid-template-columns: var(--margin-col) minmax(0, 1fr); }
  .article.has-aside > .sources { grid-column: 2; margin-top: 2rem; }
}

@media (max-width: 56rem) {
  :root { --margin-col: 0px; }
  .section { padding-top: 3rem; padding-bottom: 3rem; }
  .article, .article.has-aside { grid-template-columns: minmax(0, 1fr); }
  .article > .span-all, .article.has-aside > .sources { grid-column: 1; }
  .section .article > h2, .section-title { position: static; margin-bottom: 1.4rem; }
  .meta { grid-template-columns: repeat(3, auto); justify-content: start; gap: 1.2rem 2rem; padding: 0 0 1.4rem; }
  .fig-label { margin-bottom: 0.8rem; }
  .abstract > div, .statements > div { grid-template-columns: minmax(0, 1fr); gap: 0.3rem; }
  .sequence { grid-template-columns: minmax(0, 1fr); }
  .sequence li { padding-bottom: 1.3rem; }
  .site-footer .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 34rem) {
  .meta { grid-template-columns: minmax(0, 1fr); }
  .site-footer .cols { grid-template-columns: minmax(0, 1fr); }
  .actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 40rem) {
  html:not(.no-js) table.data[data-stack] { min-width: 0; display: block; }
  html:not(.no-js) table.data[data-stack] caption,
  html:not(.no-js) table.data[data-stack] tbody,
  html:not(.no-js) table.data[data-stack] tfoot,
  html:not(.no-js) table.data[data-stack] tr,
  html:not(.no-js) table.data[data-stack] th,
  html:not(.no-js) table.data[data-stack] td { display: block; }
  html:not(.no-js) table.data[data-stack] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  html:not(.no-js) table.data[data-stack] tbody tr { border-top: 2px solid var(--ink); padding: 0.5rem 0 0.7rem; }
  html:not(.no-js) table.data[data-stack] tbody th { border: 0; padding: 0.3rem 0; }
  html:not(.no-js) table.data[data-stack] tbody td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: 0.2rem 0; }
  html:not(.no-js) table.data[data-stack] tbody td::before { content: attr(data-label); font-weight: 600; color: var(--ink-3); }
  html:not(.no-js) table.data[data-stack] tfoot td { padding-top: 0.9rem; }
}

@media (pointer: coarse) {
  .cite { position: relative; }
  .cite::after { content: ""; position: absolute; inset: -0.8em -0.6em; }
}

@media (prefers-reduced-motion: reduce) {
  .hl { transition: none; background-size: 100% 0.34em; }
  .btn { transition: none; }
}

@media print {
  .masthead, .site-footer .cols, .skip-link, .actions { display: none; }
  body { background: #fff; font-size: 11pt; }
  .on-field { background: #fff; color: #000; }
  .hl { background-size: 100% 100%; }
}
