:root {
  --bg: #f6f5f1;
  --surface: #eeede7;
  --fg: #111111;
  --muted: #6b6a66;
  --line: #dddcd5;
  --accent: #2f6b4f;
  --term-bg: #141414;
  --term-line: transparent;
  --term-accent: #6fcf9f;
  --max: 1080px;
  color-scheme: light;

  /* Hover: the highlight builds slowly and leaves a little quicker */
  --hover-in: 0.8s;
  --hover-out: 0.5s;
  --hover-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --haze: color-mix(in srgb, var(--accent) 20%, transparent);
  --haze-strong: color-mix(in srgb, var(--accent) 45%, transparent);

  /* Visitor text preferences (set from the "aa" menu or the terminal) */
  --text-scale: 1;
  --font-body: "Inter Tight", system-ui, sans-serif;
}

:root[data-size="small"] { --text-scale: 0.9; }
:root[data-size="large"] { --text-scale: 1.12; }
:root[data-size="larger"] { --text-scale: 1.25; }

:root[data-font="serif"] { --font-body: "Newsreader", Georgia, serif; }
:root[data-font="mono"] { --font-body: "JetBrains Mono", ui-monospace, monospace; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0e0e;
    --surface: #1a1a19;
    --fg: #f2f1ec;
    --muted: #9a9993;
    --line: #2a2a28;
    --accent: #6fcf9f;
    --term-bg: #171716;
    --term-line: #2a2a28;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e0e;
  --surface: #1a1a19;
  --fg: #f2f1ec;
  --muted: #9a9993;
  --line: #2a2a28;
  --accent: #6fcf9f;
  --term-bg: #171716;
  --term-line: #2a2a28;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: calc(100% * var(--text-scale));
  scroll-padding-top: 80px;
}

/* Native smooth scrolling only as a fallback: Lenis animates scrolling itself when it runs */
@media (prefers-reduced-motion: no-preference) {
  html:not(.lenis) { scroll-behavior: smooth; }
}

/* Lenis' recommended base styles */
html.lenis,
html.lenis body { height: auto; }

.lenis [data-lenis-prevent] { overscroll-behavior: contain; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-transform: lowercase;
}

a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
button, input { text-transform: inherit; }

.container {
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: 24px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav { display: flex; align-items: center; gap: 28px; }

.header-controls { display: flex; align-items: center; gap: 8px; }

.nav a {
  font-size: 0.9375rem;
  color: var(--muted);
  transition: color var(--hover-out) var(--hover-ease), text-shadow var(--hover-out) var(--hover-ease);
}

.nav a:hover {
  color: var(--fg);
  text-shadow: 0 0 14px var(--haze-strong);
  transition-duration: var(--hover-in);
}

/* Hero */
.hero {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: 24px;
}

.terminal {
  max-width: 820px;
  border-radius: 14px;
  border: 1px solid var(--term-line);
  background: var(--term-bg);
  color: #ececec;
  font-family: "JetBrains Mono", monospace;
  box-shadow: 0 30px 60px -24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.terminal-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--term-bg) 88%, #fff);
}

.terminal-bar i { width: 12px; height: 12px; border-radius: 50%; background: #ff5f57; }
.terminal-bar i:nth-child(2) { background: #febc2e; }
.terminal-bar i:nth-child(3) { background: #28c840; }

.terminal-bar span {
  flex: 1;
  text-align: center;
  margin-right: 52px;
  font-size: 0.8125rem;
  color: #8a8a8a;
}

.terminal-body { padding: 28px 28px 24px; }

.terminal-line { font-size: clamp(0.95rem, 0.8rem + 0.5vw, 1.1rem); line-height: 1.7; }
.terminal .prompt { color: var(--term-accent); }
.terminal .path { color: #8a8a8a; }

.name {
  margin-top: 14px;
  font-size: clamp(2rem, 1rem + 4.5vw, 4.4rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.05;
  display: grid;
}

/* The invisible full name reserves the final size, so the terminal never grows while typing */
.name-ghost,
.name-typed { grid-area: 1 / 1; }

.name-ghost { visibility: hidden; }

.tagline {
  margin-top: 12px;
  font-size: clamp(0.95rem, 0.8rem + 0.5vw, 1.1rem);
  color: #8a8a8a;
  min-height: 1.6em;
}

/* Interactive session: a fixed-height area that scrolls, so the window never resizes */
.term-session {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  height: calc(8 * 1.7em + 14px);
  overflow-y: auto;
  font-size: clamp(1rem, 0.85rem + 0.4vw, 1.1rem);
  line-height: 1.7;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
}

.term-session:not([data-ready]) .term-input-line { visibility: hidden; }

.term-out {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term-out .muted { color: #8a8a8a; }
.term-out .accent { color: var(--term-accent); }
.term-out .error { color: #ff7b72; }

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

.term-input-line {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  cursor: text;
}

.term-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: none;
  color: inherit;
  font: inherit;
  caret-color: var(--term-accent);
}

.term-input::placeholder { color: #5c5c5c; }

.term-session[data-mode="game"] { overflow: hidden; }

.term-session[data-mode="game"] .term-log,
.term-session[data-mode="game"] .term-input-line { display: none; }

.term-game {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.term-game-status {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  flex: none;
  margin-bottom: 6px;
  white-space: nowrap;
}

.term-game-status span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.term-game canvas {
  display: block;
  flex: 1;
  min-height: 0;
  width: 100%;
  touch-action: none;
}

.term-game button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--term-accent);
  font: inherit;
  cursor: pointer;
}

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 0.95em;
  background: currentColor;
  vertical-align: -0.1em;
  margin-left: 0.04em;
  animation: blink 1s steps(1) infinite;
}

.cursor.bar { width: 0.08em; }
.cursor[hidden] { display: none; }

@keyframes blink { 50% { opacity: 0; } }

.hero-tagline {
  margin-top: 20px;
  font-size: clamp(1rem, 0.9rem + 0.3vw, 1.15rem);
  color: var(--muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  height: 46px;
  padding-inline: 22px;
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 500;
  transition:
    transform var(--hover-out) var(--hover-ease),
    border-color var(--hover-out) var(--hover-ease),
    box-shadow var(--hover-out) var(--hover-ease);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 32px -8px var(--haze-strong);
  transition-duration: var(--hover-in);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-ghost {
  border: 1px solid var(--line);
}

.btn-ghost:hover { border-color: var(--fg); }

/* Sections */
.section {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 48px;
  padding-block: 96px;
  border-top: 1px solid var(--line);
}

.section-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  padding-top: 6px;
}

.label-prefix { color: var(--accent); }

/* Scroll reveals: labels type themselves, then the section's content rises in, one piece after another */
:root {
  --reveal-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: no-preference) {
  .js .section:not(.is-visible) .section-label { visibility: hidden; }

  /* Only while revealing, so elements keep their own hover transitions afterwards */
  .js .section:not(.is-done) .section-body > * {
    transition:
      opacity 1s var(--reveal-ease),
      transform 1s var(--reveal-ease);
    transition-delay: calc(0.35s + var(--i, 0) * 0.09s);
  }

  .js .section:not(.is-visible) .section-body > * {
    opacity: 0;
    transform: translateY(18px);
  }
}

/* Characters not yet typed hold their space, so nothing shifts while typing */
.section-label .ch:not(.is-typed) { visibility: hidden; }

.section-label.is-typing .is-cursor::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.05em;
  vertical-align: -0.15em;
  background: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.section-body > * + * { margin-top: 20px; }

.lead {
  font-size: clamp(1.25rem, 1rem + 0.8vw, 1.6rem);
  line-height: 1.4;
  letter-spacing: -0.01em;
  text-wrap: pretty;
}

.section-body p:not(.lead) { color: var(--muted); max-width: 62ch; }

.facts {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.facts div {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  column-gap: 16px;
}

.facts dt {
  grid-row: span 2;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.875rem;
  color: var(--muted);
  padding-top: 0.15em;
}

.facts dd { grid-column: 2; }

.skills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 8px;
}

.skills li {
  font-size: 0.875rem;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
}

/* Lists (work + experience) */
.list.section-body > * + * { margin-top: 0; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 24px;
  padding-block: 24px;
  border-bottom: 1px solid var(--line);
}

.list li:first-child .row,
.list li.row:first-child { padding-top: 0; }

.list li:last-child .row,
.list li.row:last-child { border-bottom: 0; padding-bottom: 0; }

.row h3 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.row p { color: var(--muted); margin-top: 4px; }

.meta {
  font-size: 0.875rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

a.row {
  position: relative;
  isolation: isolate;
}

a.row::before {
  content: "";
  position: absolute;
  inset: -6px -12px;
  z-index: -1;
  border-radius: 18px;
  background: radial-gradient(ellipse closest-side, var(--haze), transparent);
  opacity: 0;
  transition: opacity var(--hover-out) var(--hover-ease);
  pointer-events: none;
}

a.row:hover::before {
  opacity: 1;
  transition-duration: var(--hover-in);
}

a.row h3::after {
  content: " ↗";
  display: inline-block;
  color: var(--muted);
  transition: transform var(--hover-out) var(--hover-ease), color var(--hover-out) var(--hover-ease);
}

a.row:hover h3::after {
  transform: translate(2px, -2px);
  color: var(--accent);
  transition-duration: var(--hover-in);
}

/* Contact */
#contact .section-body { container-type: inline-size; }

.email {
  display: inline-block;
  font-size: min(3rem, 6.8cqi);
  font-weight: 600;
  letter-spacing: -0.03em;
  border-bottom: 2px solid var(--line);
  transition: border-color var(--hover-out) var(--hover-ease), text-shadow var(--hover-out) var(--hover-ease);
}

.email:hover {
  border-color: var(--accent);
  text-shadow: 0 0 24px var(--haze-strong);
  transition-duration: var(--hover-in);
}

.socials {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 16px;
}

.socials a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 104px;
  padding: 18px 20px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--muted);
  font-size: 0.875rem;
  transition:
    color var(--hover-out) var(--hover-ease),
    border-color var(--hover-out) var(--hover-ease),
    background-color var(--hover-out) var(--hover-ease),
    box-shadow var(--hover-out) var(--hover-ease),
    transform var(--hover-out) var(--hover-ease);
}

.socials a:hover {
  color: var(--fg);
  border-color: var(--haze-strong);
  background-color: color-mix(in srgb, var(--accent) 6%, transparent);
  box-shadow: 0 12px 34px -12px var(--haze-strong);
  transform: translateY(-2px);
  transition-duration: var(--hover-in);
}

.socials svg { transition: color var(--hover-out) var(--hover-ease); }

.socials svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.socials a:hover svg { color: var(--accent); transition-duration: var(--hover-in); }

/* Footer */
.site-footer {
  display: flex;
  justify-content: space-between;
  padding-block: 32px;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
  color: var(--muted);
}

.site-footer a { transition: color var(--hover-out) var(--hover-ease), text-shadow var(--hover-out) var(--hover-ease); }

.site-footer a:hover {
  color: var(--fg);
  text-shadow: 0 0 14px var(--haze-strong);
  transition-duration: var(--hover-in);
}

/* Mobile */
@media (max-width: 720px) {
  .container { padding-inline: 16px; }
  .nav { gap: 18px; }
  .nav a[href="#experience"],
  .nav a[href="#publications"] { display: none; }
  .facts div { grid-template-columns: 1fr; }
  .facts dt { grid-row: auto; }
  .facts dd { grid-column: 1; }
  .hero { min-height: auto; padding-block: 56px 64px; }
  .terminal-body { padding: 22px 18px 18px; }
  .terminal-bar span { margin-right: 0; text-align: right; }
  .section {
    grid-template-columns: 1fr;
    gap: 20px;
    padding-block: 64px;
  }
  .row { flex-direction: column; gap: 4px; }
  .meta { order: -1; }
  .socials li { flex: 1; }
  .socials a { min-width: 0; padding-inline: 8px; }
}

/* Header menus (colour, text) */
.menu { position: relative; }

.menu-popover {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 210px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.3);
}

.menu-popover[hidden] { display: none; }

.menu-title {
  padding: 4px 8px 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.menu-popover button {
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color var(--hover-out) var(--hover-ease);
}

.menu-popover button:hover {
  background: var(--surface);
  transition-duration: var(--hover-in);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  margin-bottom: 10px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
}

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

.segmented button {
  display: grid;
  place-items: center;
  height: 34px;
  padding: 0;
  line-height: 1;
}

.segmented button:hover { background: color-mix(in srgb, var(--bg) 55%, transparent); }

.segmented button[aria-checked="true"] {
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Header icon buttons (menus, theme toggle) */
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    color var(--hover-out) var(--hover-ease),
    border-color var(--hover-out) var(--hover-ease),
    box-shadow var(--hover-out) var(--hover-ease);
}

.icon-btn:hover {
  color: var(--fg);
  border-color: var(--haze-strong);
  box-shadow: 0 0 18px var(--haze);
  transition-duration: var(--hover-in);
}

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

/* Show the icon for the mode you'd switch to */
.icon-sun { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

body { transition: background-color 0.3s, color 0.3s; }

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

/* Very narrow phones: tighten the header so links and controls share one row */
@media (max-width: 420px) {
  .nav { gap: 14px; }
  .header-controls { gap: 6px; }
}

/* Reduced motion: keep the slow fades, drop the lifts */
@media (prefers-reduced-motion: reduce) {
  .btn:hover,
  .socials a:hover,
  a.row:hover h3::after { transform: none; }
}
