:root {
  --bg: #ffffff;
  --bg-2: #f5f5f4;
  --text: #1c1c1c;
  --text-2: #555;
  --text-3: #8a8a8a;
  --line: #e4e4e2;
  --link: #0b57d0;
  --alpha: #d0402b;
  --water: #3b74c9;
  --sun: #e0a526;
  --ok: #2e7d32;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131313; --bg-2: #1c1c1c;
    --text: #e8e8e6; --text-2: #b0b0ad; --text-3: #85857f;
    --line: #2c2c2a; --link: #8ab4f8;
    --alpha: #ef6b54; --water: #6b9be0; --sun: #e8b54a; --ok: #81c784;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131313; --bg-2: #1c1c1c;
  --text: #e8e8e6; --text-2: #b0b0ad; --text-3: #85857f;
  --line: #2c2c2a; --link: #8ab4f8;
  --alpha: #ef6b54; --water: #6b9be0; --sun: #e8b54a; --ok: #81c784;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  overflow-wrap: break-word;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* layout: sidebar + content */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 64px;
}
.side { position: sticky; top: 88px; align-self: start; }
.content { max-width: 680px; }
@media (max-width: 820px) {
  .page { grid-template-columns: 1fr; gap: 32px; padding: 32px 16px 64px; }
  .side { position: static; }
}

.side h1 { font-size: 24px; line-height: 1.2; margin: 0 0 6px; }
.side .role { margin: 0 0 14px; color: var(--text-2); }
.side .where { margin: 0 0 18px; color: var(--text-3); font-size: 14px; }
.side ul { list-style: none; padding: 0; margin: 0 0 18px; font-size: 15px; }
.side li { margin: 3px 0; }
.side .label { font-size: 13px; color: var(--text-3); margin: 0 0 4px; }
.side .back { font-size: 14px; display: inline-block; margin-bottom: 18px; }
@media (max-width: 820px) {
  .side ul.links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
}

/* content */
.intro p { margin: 0 0 14px; font-size: 17px; }
section { margin-top: 48px; }
h2 { font-size: 20px; margin: 0 0 16px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
h3 { font-size: 16px; margin: 0; }
p { margin: 0 0 12px; }
ul { margin: 0; padding-left: 20px; }
li { margin-bottom: 6px; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }

.entry { margin-bottom: 26px; }
.entry-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.h3-note { font-weight: 400; color: var(--text-2); }
.entry-head .date { color: var(--text-3); font-size: 14px; white-space: nowrap; }
.entry .sub { color: var(--text-2); margin: 2px 0 8px; font-size: 15px; }

.paper { margin-bottom: 22px; }
.paper .t { font-weight: 600; }
.paper .by { color: var(--text-2); font-size: 15px; margin: 2px 0; }
.paper .links { font-size: 14px; }
.paper .links a { margin-right: 10px; }
.paper p.note { font-size: 15px; margin-top: 6px; }

.skills { display: grid; grid-template-columns: 110px 1fr; gap: 6px 16px; margin: 0; }
.skills dt { color: var(--text-3); font-size: 15px; }
.skills dd { margin: 0; }
@media (max-width: 520px) { .skills { grid-template-columns: 1fr; gap: 0; } .skills dd { margin-bottom: 10px; } }

footer { margin-top: 64px; color: var(--text-3); font-size: 14px; }

/* ---- alpha doodles ---- */
.doodle { margin: 28px 0 36px; }
.doodle svg { display: block; width: 100%; max-width: 660px; height: auto; }
.doodle figcaption { margin-top: 6px; }
.doodle text { font-family: var(--hand); font-size: 20px; fill: var(--text); }
.doodle .d-small { font-size: 16px; fill: var(--text-2); }
.doodle .d-sub { font-size: 17px; fill: var(--text-2); }
.doodle .d-alpha { font-size: 26px; fill: var(--alpha); }
.doodle .d-alpha-in, .doodle .d-em { fill: var(--alpha); }
.d-line { fill: none; stroke: var(--text); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.d-thin { stroke-width: 1.8; }
.d-rail { stroke: var(--text-3); stroke-width: 5; }
.d-dash { stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 5 6; }
.d-red-stroke { fill: none; stroke: var(--alpha); stroke-width: 2.5; }
.d-ink-stroke { fill: none; stroke: var(--text); stroke-width: 1.8; }
.d-red-fill { fill: var(--alpha); stroke: var(--alpha); }
.d-sun { fill: var(--sun); stroke: var(--text); }
.d-sun-stroke { fill: none; stroke: var(--sun); stroke-width: 3; }
.d-fill-ink { fill: var(--text); }
.d-paper { fill: var(--bg); }
.d-water { fill: var(--water); fill-opacity: .16; stroke: var(--water); }
.d-fish { fill: var(--water); stroke: var(--water); stroke-width: 1; }
.quant-box { background: var(--bg-2); border-radius: 8px; padding: 16px 20px 8px; margin-top: 8px; }
.quant-box h3 { margin-bottom: 8px; }
.quant-box .eq { font-family: var(--mono); font-size: 15px; margin: 4px 0 12px; }
.quant-box .eq b { color: var(--alpha); }
.quant-box li { font-size: 15px; }

/* ---- top bar ---- */
html { scroll-padding-top: 72px; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1040px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { font-weight: 700; font-size: 20px; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 20px; font-size: 15px; }
.nav a { color: var(--text-2); padding: 6px 0; }
.nav a:hover { color: var(--text); text-decoration: none; }
.theme-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.theme-btn:hover { background: var(--bg-2); }
.theme-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn .i-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .i-moon { display: none; }
}
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }
@media (max-width: 820px) {
  .topbar-in { padding: 12px 16px; flex-wrap: wrap; }
  .nav { gap: 14px; font-size: 14px; flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .nav a[href="#papers"], .nav a[href="#projects"] { display: none; }
}

/* ---- contact ---- */
.contact-mail { font-size: 18px; font-weight: 600; margin: 4px 0 10px; }
.contact-links { list-style: none; padding: 0; display: flex; gap: 18px; flex-wrap: wrap; }

/* ---- sidebar ---- */
.side { padding-right: 8px; }
.side h1 { font-size: 26px; margin: 0 0 4px; }
.side .role { color: var(--text-2); margin: 0 0 18px; }
.ic { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.facts { list-style: none; padding: 0; margin: 0 0 20px; font-size: 14px; color: var(--text-2); }
.facts li { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 8px; line-height: 1.45; }
.facts .ic { margin-top: 1px; color: var(--text-3); }
.social { list-style: none; padding: 0; margin: 0 0 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.social li { margin: 0; }
.social li.wide { grid-column: 1 / -1; }
.social a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: 14px; }
.social a:hover { background: var(--bg-2); text-decoration: none; }
.side .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 0 0 6px; }
.cv { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.cv li { margin: 0 0 4px; }
.cv a { display: inline-flex; align-items: center; gap: 8px; }
@media (max-width: 820px) {
  .social { display: flex; flex-wrap: wrap; }
  .social li.wide { grid-column: auto; }
}
@media (max-width: 480px) { .social { display: grid; grid-template-columns: 1fr 1fr; } .social li.wide { grid-column: 1 / -1; } }

/* ---- quote + visitor card ---- */
.quote-card { margin-top: 56px; display: flex; align-items: center; gap: 16px; padding: 18px 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.q-mark { width: 20px; height: 20px; flex: none; align-self: flex-start; margin-top: 2px; fill: none; stroke: var(--text-3); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.q { margin: 0; flex: 1; min-width: 0; }
.q blockquote { margin: 0; font-weight: 600; font-size: 15px; }
.q figcaption { color: var(--text-3); font-size: 14px; margin-top: 2px; }
.visits { margin: 0; padding-left: 20px; border-left: 1px solid var(--line); color: var(--text-2); font-size: 14px; white-space: nowrap; }
.visits b { color: var(--text); font-size: 16px; }
.visits sup { font-size: 10px; font-weight: 700; color: var(--text); }
@media (max-width: 560px) {
  .quote-card { flex-wrap: wrap; }
  .visits { flex-basis: 100%; border-left: 0; border-top: 1px solid var(--line); padding: 10px 0 0 36px; }
}
footer { margin-top: 20px; }

.mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; flex: none; background: var(--text); }
.mark svg { width: 24px; height: 24px; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.mark .m-code { stroke: var(--bg); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mark .m-wick { stroke: var(--bg); stroke-width: 1.5; stroke-linecap: round; }
.mark .m-body { fill: var(--bg); }
.mark:hover { text-decoration: none; opacity: .85; }

/* small phones (iPhone SE and similar) */
@media (max-width: 360px) {
  .page { padding-left: 12px; padding-right: 12px; }
  .topbar-in { padding-left: 12px; padding-right: 12px; }
  .nav { gap: 10px; }
  .contact-mail { font-size: 16px; }
}
/* touch screens: no sticky hover states, comfortable tap targets */
@media (hover: none) {
  .social a:hover, .theme-btn:hover { background: transparent; }
  .theme-btn { width: 40px; height: 40px; }
}

/* ---- preloader: a wobbly circle drawing itself around the logo ---- */
#preloader { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; display: flex;
  align-items: center; justify-content: center; background: var(--bg); transition: opacity .45s ease, visibility .45s ease; }
#preloader.done { opacity: 0; visibility: hidden; }
.pl-wrap { position: relative; width: 132px; height: 132px; display: flex; align-items: center; justify-content: center; }
.pl-ring { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: visible; animation: pl-spin 3.2s linear infinite; }
.pl-stroke { fill: none; stroke: var(--text); stroke-linecap: round; stroke-dasharray: 100; }
.pl-s1 { stroke-width: 2.4; animation: pl-draw 1.6s cubic-bezier(.6, .1, .3, 1) infinite; }
.pl-s2 { stroke-width: 1.2; opacity: .45; animation: pl-draw 1.6s cubic-bezier(.6, .1, .3, 1) infinite; animation-delay: -.12s; }
@keyframes pl-draw { 0% { stroke-dashoffset: 100; } 55% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -100; } }
@keyframes pl-spin { to { transform: rotate(360deg); } }
.pl-mark { width: 60px; height: 60px; border-radius: 15px; background: var(--text); display: flex; align-items: center; justify-content: center; }
.pl-mark svg { width: 42px; height: 42px; }
.pl-code { fill: none; stroke: var(--bg); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pl-wick { fill: none; stroke: var(--bg); stroke-width: 1.5; stroke-linecap: round; }
.pl-body { fill: var(--bg); }
@media (prefers-reduced-motion: reduce) {
  .pl-ring, .pl-stroke { animation: none; }
  .pl-stroke { stroke-dashoffset: 0; }
  #preloader { transition: none; }
}

/* ---- 404 ---- */
.nf { min-height: calc(100vh - 140px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 16px; }
.nf .code { font-family: var(--mono); font-size: 14px; color: var(--text-3); margin: 0 0 8px; }
.nf h1 { font-size: 32px; margin: 0 0 10px; }
.nf p { color: var(--text-2); max-width: 440px; }
.nf .home { display: inline-flex; margin-top: 12px; padding: 9px 16px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
.nf .home:hover { background: var(--bg-2); text-decoration: none; }

/* ---- full-page background: Monte Carlo price paths with the alpha path, from the GitHub README header ---- */
:root { --bg-line: rgba(0, 0, 0, .085); --bg-grid: rgba(0, 0, 0, .025); --bg-hero: #d98e0f; --bg-hero-o: .42; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg-line: rgba(255, 255, 255, .1); --bg-grid: rgba(255, 255, 255, .03); --bg-hero: #f5b041; --bg-hero-o: .5; }
}
:root[data-theme="dark"] { --bg-line: rgba(255, 255, 255, .1); --bg-grid: rgba(255, 255, 255, .03); --bg-hero: #f5b041; --bg-hero-o: .5; }
#bg-graph { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background-image: linear-gradient(var(--bg-grid) 1px, transparent 1px), linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 48px 48px; }
#bg-graph svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: block; }
#bg-graph path, #bg-graph line { fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.bg-paths path { stroke: var(--bg-line); stroke-width: 1.2; }
.bg-base { stroke: var(--bg-line); stroke-width: 1; stroke-dasharray: 3 5; }
#bg-graph .bg-hero { stroke: var(--bg-hero); stroke-opacity: var(--bg-hero-o); stroke-width: 2.2; }
.bg-paths, #bg-graph .bg-hero { animation: bg-draw 2.8s ease-out .5s both; }
@keyframes bg-draw { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.bg-dot, .bg-alpha { position: absolute; animation: bg-pop .4s ease-out 3.2s both; }
.bg-dot { left: 97%; top: 14%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--bg-hero); opacity: var(--bg-hero-o); }
.bg-alpha { left: 97%; top: 14%; margin: -26px 0 0 -20px; font-size: 15px; font-weight: 700; color: var(--bg-hero); }
@keyframes bg-pop { from { opacity: 0; } }
.social a, .doodle svg { background: var(--bg); }
.doodle svg { border-radius: 8px; }
.bg-eq { position: absolute; right: 16px; bottom: 10px; font-size: 12px; font-style: italic; color: var(--text-3); opacity: .7; }
@media (max-width: 820px) {
  .bg-eq { display: none; }
  /* text sits over more of the graph on narrow screens */
  #bg-graph .bg-hero { stroke-opacity: .28; stroke-width: 1.6; }
  .bg-dot, .bg-alpha { opacity: .45; }
  /* phones and tablets: skip the draw-in, it repaints the whole screen */
  .bg-paths, #bg-graph .bg-hero, .bg-dot, .bg-alpha { animation: none; }
}
@media (prefers-reduced-motion: reduce) { .bg-paths, #bg-graph .bg-hero, .bg-dot, .bg-alpha { animation: none; } }
@media print { #bg-graph { display: none; } }
