/* Shared stylesheet — scientific / LaTeX-article look, light + dark */
:root {
  --bg: #fcfcf7;
  --ink: #1a1a1a;
  --muted: #5a5a55;
  --faint: #8a8a82;
  --rule: #1a1a1a;
  --grid: rgba(26, 26, 26, 0.12);
  --grid-strong: rgba(26, 26, 26, 0.35);
  --panel: #f4f3ea;
  --link: #1f4e8c;
  --c-blue: #1f5fa8;
  --c-amber: #b7791f;
  --c-green: #2f7d3a;
  --c-red: #9b1c1c;
  --z-hypoxic: #8a94a3;
  --z-normoxic: #5fae6b;
  --z-hyperoxic: #4aa3c4;
  --z-critical: #d9a22b;
  --z-toxic: #9f1239;
  --font: 'Latin Modern Roman', 'LM Roman 10', 'Computer Modern', 'CMU Serif', 'STIX Two Text', 'Libertinus Serif', Georgia, 'Times New Roman', serif;
  --mono: 'Latin Modern Mono', 'CMU Typewriter Text', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a0a07;
  --ink: #e8e6dd;
  --muted: #a9a79d;
  --faint: #7d7b72;
  --rule: #e8e6dd;
  --grid: rgba(232, 230, 221, 0.12);
  --grid-strong: rgba(232, 230, 221, 0.35);
  --panel: #13130e;
  --link: #8ab8f0;
  --c-blue: #6cb6ff;
  --c-amber: #e5b44b;
  --c-green: #5fc17a;
  --c-red: #ff7b7b;
  --z-hypoxic: #64748b;
  --z-normoxic: #4ade80;
  --z-hyperoxic: #22d3ee;
  --z-critical: #fbbf24;
  --z-toxic: #be214f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  font-size: 1.08rem;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s, color .2s;
}
::selection { background: color-mix(in srgb, var(--link) 25%, transparent); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
p { text-align: justify; hyphens: auto; -webkit-hyphens: auto; margin: 0 0 1rem; }
code, kbd, samp, pre { font-family: var(--mono); font-variant-numeric: normal; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

/* ---------- background fish (fish.js) ---------- */
#fish-bg, #pages-bg, #math-bg, #alps-bg, #section-bg, #orbitals-bg, #cs-bg, #tree-bg, #physics-bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }

/* ---------- header / nav ---------- */
#theme-toggle {
  background: none; color: var(--ink); border: 0;
  width: 2rem; height: 2rem; padding: 0; cursor: pointer; border-radius: 0;
  display: inline-flex; align-items: center; justify-content: center;
  position: fixed; top: 1rem; right: 1rem; z-index: 10;
}
#theme-toggle:hover { opacity: .6; }
/* CSS-drawn icon: sun in light mode, moon in dark mode */
.theme-icon { position: relative; display: block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.theme-icon::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 2px; height: 2px; background: currentColor;
  box-shadow: 0 -8px, 0 8px, 8px 0, -8px 0, 6px 6px, -6px -6px, 6px -6px, -6px 6px;
}
:root[data-theme="dark"] .theme-icon {
  width: 14px; height: 14px; background: none; box-shadow: inset -5px -3px 0 0 currentColor; transform: rotate(-20deg);
}
:root[data-theme="dark"] .theme-icon::after { display: none; }

/* ---------- page ---------- */
.page { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem 3rem; }
.page.narrow { max-width: 800px; }
h1.paper-title { font-size: clamp(1.6rem, 3.8vw, 2.25rem); font-weight: normal; line-height: 1.2; text-align: center; margin: 1.2rem 0 .6rem; letter-spacing: -.005em; text-wrap: balance; }
.byline { text-align: center; color: var(--muted); font-size: 1rem; margin-bottom: 1.8rem; font-style: italic; }
.byline::after { content: ""; display: block; width: 3rem; margin: 1.2rem auto 0; border-top: 1px solid var(--ink); }
.abstract { max-width: 600px; margin: 0 auto 2.2rem; font-size: .98rem; text-align: justify; hyphens: auto; -webkit-hyphens: auto; padding: 0 1.5rem; }
.abstract strong { display: block; text-align: center; font-weight: bold; font-variant: small-caps; text-transform: lowercase; letter-spacing: .1em; font-size: 1.05rem; margin-bottom: .35rem; }
h2.section {
  font-weight: normal; font-size: 1.35rem; font-variant: small-caps; text-transform: lowercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--rule); padding-bottom: .3rem; margin: 2.5rem 0 1.2rem;
}
h2.section:first-of-type { margin-top: 0; }
h3.subsection { font-weight: normal; font-style: italic; font-size: 1.05rem; color: var(--muted); margin: 1.4rem 0 .5rem; }
.biblio:has(li) + .in-prep { display: none; }
sub, sup { line-height: 0; }
.eq {
  text-align: center; margin: 1.2rem 0; font-size: 1.1rem; font-style: italic;
  display: flex; justify-content: center; align-items: baseline; gap: 1rem; flex-wrap: wrap;
}
.eq .tag { font-style: normal; color: var(--muted); }
.eq .param { font-style: normal; font-size: .85rem; color: var(--muted); width: 100%; text-align: center; }

/* ---------- lists (certifications, contents) ---------- */
.cert-list { list-style: none; padding: 0; margin: 0; counter-reset: item; }
.cert-list li { display: flex; justify-content: space-between; align-items: baseline; padding: .35rem 0; }
.cert-list li::before { content: counter(item) ". "; counter-increment: item; font-style: italic; color: var(--muted); min-width: 2rem; display: inline-block; }
.cert-list li .t { flex: 1; }
.cert-date { font-style: italic; font-size: .92rem; margin-left: 1.5rem; white-space: nowrap; }
.planned-cert { color: var(--muted); font-style: italic; opacity: .75; }
.planned-cert::before { content: "(" counter(item) ") " !important; }

.toc { list-style: none; padding: 0; margin: 0; }
.toc li { display: flex; align-items: baseline; gap: .5rem; padding: .4rem 0; }
.toc a { text-decoration-thickness: 1px; }
.toc a:hover { text-decoration-thickness: 2px; }
.toc .num { min-width: 2.2rem; flex-shrink: 0; color: var(--muted); font-style: normal; font-variant-numeric: lining-nums; }
.toc .dots { flex: 1; border-bottom: 1px dotted var(--faint); transform: translateY(-4px); }
.toc .desc { display: block; font-size: .9rem; color: var(--muted); }
.toc .sub { margin-left: 2.2rem; }
.toc .desc { text-align: left; }

/* ---------- figures ---------- */
figure.fig { margin: 1.5rem 0 0; }
figure.fig canvas { display: block; width: 100%; height: clamp(360px, 62vh, 640px); background: transparent; border-top: 1px solid var(--grid-strong); border-bottom: 1px solid var(--grid-strong); }
figcaption { font-size: .95rem; color: var(--ink); margin-top: .7rem; text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
figcaption b { font-weight: bold; font-variant-numeric: lining-nums; }
.legend-row { display: flex; gap: .4rem 1.5rem; flex-wrap: wrap; justify-content: center; font-size: .9rem; color: var(--muted); margin: 1rem 0 .5rem; }
.legend-item { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.legend-item .limits { font-style: italic; }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.line-swatch { width: 20px; height: 2px; flex-shrink: 0; }

.controls { display: flex; gap: 1rem 1.6rem; flex-wrap: wrap; justify-content: center; align-items: flex-end; margin: 1rem 0; padding: .7rem 1rem; background: var(--panel); border: 1px solid var(--grid-strong); }
.field { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field input {
  font: inherit; font-size: 1rem; letter-spacing: 0; text-transform: none; color: var(--ink);
  background: var(--bg); border: 1px solid var(--grid-strong); padding: .2rem .5rem; width: 7rem; text-align: right;
  font-variant-numeric: tabular-nums; border-radius: 0;
}
.field input:focus { outline: 2px solid var(--link); outline-offset: -1px; }
.field input.manual-override { color: var(--c-amber); }
.field .unit { text-transform: none; letter-spacing: 0; }

.tips { display: flex; flex-wrap: wrap; gap: .4rem 1.6rem; justify-content: center; font-size: .9rem; color: var(--muted); margin: .5rem 0 0; }
.tips code { font-family: inherit; font-style: italic; color: var(--ink); }

.pager a { text-decoration: none; }
.pager a:hover { text-decoration: underline; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: .8rem; border-top: 1px solid var(--rule); font-size: .95rem; }

.site-footer { max-width: 960px; margin: 0 auto; padding: 1rem 1.5rem 2rem; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--grid-strong); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---------- cheatsheets (gists) ---------- */
.gist { margin-top: 2.5rem; }
.gist h3 { font-weight: normal; font-size: 1.15rem; border-bottom: 1px solid var(--grid-strong); padding-bottom: .25rem; margin: 0 0 1rem; display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.gist h3 .num { color: var(--muted); font-style: italic; }
.gist-date { margin-left: auto; font-size: .85rem; font-style: italic; color: var(--muted); }
.gist-code { background: var(--panel); border-left: 3px solid var(--grid-strong); padding: .8rem 1rem; overflow-x: auto; font-size: .85rem; line-height: 1.5; margin: 0; }
.gist-md pre { background: var(--panel); border-left: 3px solid var(--grid-strong); padding: .8rem 1rem; overflow-x: auto; font-size: .85rem; line-height: 1.5; }
.hljs-comment, .hljs-quote { color: var(--faint); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-meta .hljs-keyword { color: #a626a4; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: var(--c-green); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable.constant_ { color: var(--c-amber); }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--c-blue); }
.hljs-built_in, .hljs-type, .hljs-title.class_, .hljs-attribute { color: #0e7c86; }
.hljs-variable, .hljs-template-variable, .hljs-params, .hljs-attr { color: var(--c-red); }
.hljs-meta, .hljs-link, .hljs-selector-id, .hljs-selector-class { color: var(--link); }
.hljs-deletion { color: var(--c-red); }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: bold; }
:root[data-theme="dark"] .hljs-keyword, :root[data-theme="dark"] .hljs-selector-tag, :root[data-theme="dark"] .hljs-literal { color: #d79bf0; }
:root[data-theme="dark"] .hljs-built_in, :root[data-theme="dark"] .hljs-type, :root[data-theme="dark"] .hljs-title.class_, :root[data-theme="dark"] .hljs-attribute { color: #56d4dd; }
.gist-md blockquote { margin: 1rem 0; padding: 0 1rem; border-left: 2px solid var(--grid-strong); color: var(--muted); }
.gist-md code { font-size: .85em; }
.gist-md :not(pre) > code { background: var(--panel); padding: .05em .3em; }
.gist-md table { border-collapse: collapse; display: block; overflow-x: auto; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-variant-numeric: lining-nums tabular-nums; }
.gist-md th { border-bottom: 1px solid var(--ink); font-weight: bold; text-align: left; }
.gist-md th, .gist-md td { padding: .3rem .8rem; }
.gist-md img, .gist-img { max-width: 100%; }
.gist-err { color: var(--c-red); }

@media (max-width: 640px) {
  body { font-size: 1rem; }
  .page { padding: 1.4rem 1rem 2rem; }
  .cert-list li { flex-wrap: wrap; font-size: .95rem; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } body { transition: none; } }
@media print {
  a { color: inherit; text-decoration: none; }
  :root, :root[data-theme="dark"] { --bg: #fff; --ink: #000; --muted: #333; --rule: #000; }
  #theme-toggle, .site-nav, .controls, #fish-bg, #pages-bg, #math-bg, #alps-bg, #section-bg, #orbitals-bg, #cs-bg, #tree-bg, #physics-bg { display: none; }
  body { font-size: 11pt; }
}

/* ---------- range / select controls ---------- */
.field select { font: inherit; font-size: 1rem; letter-spacing: 0; text-transform: none; color: var(--ink); background: var(--bg); border: 1px solid var(--grid-strong); padding: .2rem .5rem; border-radius: 0; min-width: 9rem; }
.field input[type="range"] { width: 9rem; padding: 0; accent-color: var(--ink); }
.field b { font-weight: normal; color: var(--ink); text-transform: none; letter-spacing: 0; font-variant-numeric: lining-nums; }

/* 3D site map (home page) */
.sitemap-wrap { position: relative; background: transparent; overflow: hidden; }
.toc .sub2 { margin-left: 4.4rem; }
.toc .sub3 { margin-left: 6.6rem; }
.in-prep { color: var(--muted); }
.abstract.centered { text-align: center; }

/* ---------- about me (resume) ---------- */
.cv-head { display: flex; align-items: center; justify-content: center; gap: 1.8rem; margin: 0 0 2rem; flex-wrap: wrap; }
.cv-photo { width: 160px; height: 160px; object-fit: cover; border-radius: 50%; border: 1px solid var(--grid-strong); }
.cv-contact { list-style: none; padding: 0; margin: 0; font-size: .97rem; line-height: 1.7; }
.cv-skills { display: grid; grid-template-columns: 13rem 1fr; gap: .3rem 1.2rem; margin: 0; font-size: .97rem; }
.cv-skills dt { font-weight: bold; }
.cv-skills dd { margin: 0; }
.cv-entry { display: grid; grid-template-columns: 9.5rem 1fr; gap: 0 1.2rem; margin: 0 0 1.5rem; }
.cv-when { color: var(--muted); font-style: italic; font-size: .93rem; padding-top: .15rem; font-variant-numeric: lining-nums tabular-nums; }
.cv-what h3 { font-size: 1.06rem; margin: 0; font-weight: bold; }
.cv-what h3 a { color: inherit; }
.cv-client, .cv-where { font-weight: normal; color: var(--muted); }
.cv-role { font-style: italic; }
.cv-what ul, .cv-list { margin: .35rem 0 .35rem; padding-left: 1.15rem; }
.cv-what li, .cv-list li { margin: .12rem 0; }
.cv-note { margin: .35rem 0 0; text-align: left; }
.cv-tech { font-size: .82rem; color: var(--muted); font-family: var(--mono); }
@media (max-width: 640px) {
  .cv-skills, .cv-entry { grid-template-columns: 1fr; }
  .cv-skills dd { margin-bottom: .4rem; }
}
#sitemap { display: block; width: 100%; height: 440px; cursor: grab; touch-action: pan-y; }
#sitemap:active { cursor: grabbing; }
.sitemap-hint { font-size: .8rem; color: var(--muted); text-align: center; margin: .4rem 0 1.5rem; }
@media (max-width: 640px) { #sitemap { height: 340px; } }

/* gas cost table (gas-cost.html) */
.table-wrap { overflow-x: auto; margin: 1rem 0 0; }
.gas-table { width: 100%; border-collapse: collapse; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-size: .92rem; font-variant-numeric: lining-nums tabular-nums; }
.gas-table th { border-bottom: 1px solid var(--ink); font-weight: bold; text-align: left; white-space: nowrap; }
.gas-table th, .gas-table td { padding: .3rem .35rem; }
.gas-table .n { text-align: right; white-space: nowrap; }
.gas-table td:first-child { white-space: nowrap; }
.gas-table .role { font-size: .75rem; font-style: italic; color: var(--muted); }
.gas-table tr.first-deco td { border-top: 1px solid var(--grid-strong); }
.gas-table tr.sel td:first-child { font-weight: bold; }
.gas-table .best { color: var(--c-green); font-weight: bold; }
.gas-table tfoot td { border-top: 1px solid var(--ink); font-weight: bold; }
.gas-table input { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--grid-strong); padding: .1rem .3rem; width: 3.6rem; -moz-appearance: textfield; appearance: textfield; text-align: right; border-radius: 0; font-variant-numeric: tabular-nums; }
.gas-table input.qty { width: 2.6rem; }
.gas-table input::-webkit-inner-spin-button, .gas-table input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.btn { font: inherit; font-size: .95rem; color: var(--ink); background: var(--bg); border: 1px solid var(--grid-strong); padding: .2rem .8rem; cursor: pointer; border-radius: 0; }
.btn:hover { border-color: var(--ink); }
.refs { font-size: .92rem; padding-left: 1.5rem; }
.refs li { margin-bottom: .5rem; }
.refs a { word-break: break-word; }
