:root {
  --bg: #1e2120;
  --ink: #ece6d8;
  --muted: #aaa598;
  --faint: #7f7b72;
  --line: rgba(236, 230, 216, 0.16);
  --accent: #d67854;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

#topology {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
}

/* Keeps the text readable over the lines: darker on the left, where the content sits. */
.veil {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(30, 33, 32, 0.72) 0%, rgba(30, 33, 32, 0.35) 55%, rgba(30, 33, 32, 0) 100%);
}

.top,
main,
footer {
  position: relative;
  z-index: 2;
}

/* The page only takes the pointer where there's something to click, so the hill follows it everywhere. */
main,
footer {
  pointer-events: none;
}
main a,
main p,
main h1,
main h2,
main h3,
footer a {
  pointer-events: auto;
}

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(18px + env(safe-area-inset-top, 0px)) clamp(16px, 5vw, 56px) 18px;
}

.mark {
  font: 22px/1 var(--serif);
  text-decoration: none;
  letter-spacing: 0.04em;
}

.top nav {
  display: flex;
  gap: clamp(14px, 2.4vw, 28px);
  font: 12px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.top nav a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}

.top nav a:hover {
  color: var(--ink);
}

main {
  max-width: 1120px;
  padding: 0 clamp(16px, 5vw, 56px);
  margin-left: clamp(0px, 6vw, 120px);
}

/* ---- Hero ---- */

.hero {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding-block: 120px 80px;
}

.hero-text {
  max-width: 760px;
}

/* A small round portrait above the name, with its caption beside it. */
.portrait {
  position: relative;
  display: inline-flex;
  margin: 0 0 30px;
  pointer-events: auto;
}

.portrait img {
  width: 92px;
  height: 92px;
  flex: none;
  object-fit: cover;
  object-position: 56% 32%;
  border-radius: 50%;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 4px rgba(30, 33, 32, 0.8), 0 0 0 5px rgba(214, 120, 84, 0.35);
  transition: transform 0.4s ease;
}

.portrait:hover img {
  transform: scale(1.06);
}

/* The caption is a tooltip: it appears beside the photo on hover (or keyboard focus, or a tap). */
.portrait figcaption {
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  width: max-content;
  max-width: min(260px, 60vw);
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(30, 33, 32, 0.92);
  font: 11px/1.5 var(--mono);
  color: var(--muted);
  opacity: 0;
  transform: translate(-6px, -50%);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.portrait:hover figcaption,
.portrait:focus-within figcaption {
  opacity: 1;
  transform: translate(0, -50%);
}

.eyebrow {
  font: 12px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 22px;
}

h1 {
  font: 400 clamp(56px, 11vw, 124px) / 0.95 var(--serif);
  letter-spacing: -0.01em;
  margin: 0 0 28px;
}

.lead {
  font-size: clamp(17px, 2vw, 20px);
  line-height: 1.6;
  color: #d6d0c2;
  max-width: 34em;
  margin: 0 0 32px;
}

em {
  font-family: var(--serif);
  font-size: 1.12em;
  font-style: italic;
  color: var(--ink);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  pointer-events: auto;
  font: 13px/1 var(--mono);
  text-decoration: none;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(30, 33, 32, 0.5);
  backdrop-filter: blur(4px);
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pill svg {
  width: 14px;
  height: 14px;
  flex: none;
  opacity: 0.85;
}

.pill:hover {
  border-color: var(--accent);
  background: rgba(214, 120, 84, 0.1);
  transform: translateY(-1px);
}

.hint a {
  color: var(--muted);
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

.hint {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 56px 0 0;
  max-width: 30em;
  font: 12px/1.6 var(--mono);
  color: var(--faint);
}

.dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-1px);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  50% {
    opacity: 0.3;
  }
}

/* ---- Sections ---- */

.block {
  max-width: 760px;
  padding-block: 72px;
  border-top: 1px solid var(--line);
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.block.in {
  opacity: 1;
  transform: none;
}

h2 {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font: 400 40px/1 var(--serif);
  margin: 0 0 36px;
}

h2 span {
  font: 12px/1 var(--mono);
  color: var(--accent);
  letter-spacing: 0.08em;
}

h3 {
  font: 600 18px/1.3 var(--sans);
  margin: 0 0 4px;
}

.entry {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 8px 24px;
  margin-bottom: 40px;
}

.entry:last-child {
  margin-bottom: 0;
}

.when {
  font: 12px/1.9 var(--mono);
  color: var(--muted);
}

.sub {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
}

.entry p:not(.sub),
.contact p {
  margin: 0;
  color: #cfc9bb;
}

b {
  color: var(--ink);
  font-weight: 600;
}

/* ---- Olympiads ---- */

.medals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 12px;
}

.medal {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(30, 33, 32, 0.55);
  backdrop-filter: blur(4px);
  text-decoration: none;
  line-height: 1.45;
  transition: border-color 0.25s, transform 0.25s;
}

.medal:hover {
  border-color: rgba(236, 230, 216, 0.35);
  transform: translateY(-2px);
}

.medal .go {
  margin-left: auto;
  align-self: flex-start;
  color: var(--accent);
  font-size: 14px;
  transition: transform 0.25s;
}

.medal:hover .go {
  transform: translate(2px, -2px);
}

div.medal:hover {
  border-color: var(--line);
  transform: none;
}

.medal small {
  color: var(--muted);
  font-size: 13px;
}

.medal .where {
  color: var(--faint);
  font-size: 12px;
}

.disc {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font: 600 13px/1 var(--mono);
  color: #1a120c;
}

.bronze {
  background: radial-gradient(circle at 35% 30%, #f0c49a, #b5713f 60%, #7c4626);
  box-shadow: 0 0 0 3px rgba(181, 113, 63, 0.18);
}

.hm {
  background: radial-gradient(circle at 35% 30%, #f4f0e6, #b9b3a5 60%, #77736a);
  box-shadow: 0 0 0 3px rgba(185, 179, 165, 0.15);
  font-size: 12px;
}

.note {
  margin: 20px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.note a,
.contact a {
  color: var(--ink);
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

/* ---- Experience, teaching, honours ---- */

/* Organisation logos. Raster ones keep their own white background; the vector ones (TUM, KAIST)
   sit straight on the page. */
.org {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  flex: none;
  width: auto;
  height: 26px;
  max-width: 56px;
  object-fit: contain;
}

.logo.bare {
  height: 22px;
}

.stack {
  margin: 10px 0 0 !important;
  font: 11px/1.5 var(--mono) !important;
  letter-spacing: 0.02em;
  color: var(--faint) !important;
}

.stack a {
  color: var(--muted);
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

.plain {
  list-style: none;
  margin: 0;
  padding: 0;
}

.plain li {
  display: grid;
  grid-template-columns: 112px 1fr;
  align-items: baseline;
  gap: 24px;
  padding: 6px 0;
  color: #cfc9bb;
}

.plain .when {
  line-height: inherit;
}

.honours {
  margin-top: 28px;
}

/* ---- Discrete diffusion on text (js/tokens.js) ---- */

.tokens {
  margin: 18px 0 0;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(30, 33, 32, 0.6);
}

.tokens-line {
  margin: 0 0 12px !important;
  font: 13.5px/1.9 var(--mono);
  color: var(--ink) !important;
}

.tok {
  transition: color 0.25s;
}

.tok.noise {
  color: var(--accent);
}

.tok.mask {
  color: transparent;
  background: rgba(236, 230, 216, 0.14);
  border-radius: 3px;
}

.tokens-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font: 11px/1 var(--mono);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.tokens-modes {
  display: flex;
  gap: 6px;
}

.tokens-modes button,
.draw-button,
.draw-layer button {
  font: 11px/1 var(--mono);
  color: var(--muted);
  background: rgba(30, 33, 32, 0.6);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tokens-modes button:hover,
.draw-button:hover,
.draw-layer button:hover {
  color: var(--ink);
  border-color: rgba(236, 230, 216, 0.35);
}

.tokens-modes button[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
}

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

/* ---- Projects ---- */

.project {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(30, 33, 32, 0.6);
  backdrop-filter: blur(4px);
  transition: border-color 0.3s;
}

.project:hover {
  border-color: rgba(214, 120, 84, 0.55);
}

.shot {
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top left;
  transition: transform 0.6s ease;
}

.project:hover .shot img {
  transform: scale(1.04);
}

.info h3 {
  font: 400 24px/1.1 var(--serif);
  margin: 0 0 6px;
}

.info h3 a {
  text-decoration: none;
}

.arrow {
  display: inline-block;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--accent);
  transition: transform 0.25s;
}

.project:hover .arrow {
  transform: translate(2px, -2px);
}

.info p {
  margin: 0;
  font-size: 14.5px;
  color: #cfc9bb;
}

/* ---- Corner: the noise readout and the drawing tool (js/draw.js) ---- */

.corner {
  position: fixed;
  right: clamp(16px, 5vw, 56px);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 14px;
}

.draw-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(4px);
}

.draw-button svg {
  width: 12px;
  height: 12px;
}

#t-readout {
  margin: 0;
  font: 11px/1 var(--mono);
  color: var(--faint);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#t-readout:empty {
  display: none;
}

.draw-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(30, 33, 32, 0.35);
}

.draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.draw-bar {
  position: absolute;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 16px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(30, 33, 32, 0.92);
  font: 12px/1.4 var(--mono);
  color: var(--muted);
}

.draw-actions {
  display: flex;
  gap: 6px;
}

.draw-layer button.primary {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

.draw-layer button:disabled {
  opacity: 0.4;
  cursor: default;
}

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

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 40px clamp(16px, 5vw, 56px) calc(32px + env(safe-area-inset-bottom, 0px));
  font: 11px/1.5 var(--mono);
  color: var(--faint);
}

footer a {
  color: var(--muted);
}

/* ---- Phones ---- */

@media (max-width: 640px) {
  main {
    margin-left: 0;
  }
  .project {
    grid-template-columns: 1fr;
  }
  .plain li {
    grid-template-columns: 1fr;
    gap: 0;
  }
  #t-readout {
    display: none;
  }
  .top nav a:not(:last-child) {
    display: none;
  }
  .veil {
    background: rgba(30, 33, 32, 0.55);
  }
  .entry {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .hero {
    padding-block: 100px 64px;
  }
  .hint {
    margin-top: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .block {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .dot {
    animation: none;
  }
}
