:root {
  --bg: #ffffff;
  --text: #0a0a0a;
  --muted: #6b7280;
  --line: #e5e7eb;

  /* New UI tokens */
  --accent: #3b82f6;
  --accent-weak: #93c5fd;
  --good: #22c55e;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --text: #f5f5f5;
  --muted: #a3a3a3;
  --line: #333;

  --accent: #60a5fa;
  --accent-weak: #2563eb;
  --good: #4ade80;
}

/* Disable transitions during first paint to avoid flashes */
.no-anim *, .no-anim *::before, .no-anim *::after { transition: none !important; }

/* Always reserve scrollbar space so layout width is identical on all pages */
html { overflow-y: scroll; }

body {
  margin: 0;
  display: flex;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.65;
  transition: background 0.25s ease, color 0.25s ease;
}
@media (prefers-reduced-motion: reduce) { body { transition: none; } }

.wrap { width: min(50rem, 100%); padding: 0 1.25rem; margin: 10vh 0; }

h1 { font-size: clamp(2.5rem, 6vw, 3.25rem); margin: 0 0 0.25rem; letter-spacing: -0.01em; }
h1 a { color: inherit; text-decoration: none; border-bottom: none; }
h1 a:hover, h1 a:focus-visible { color: var(--muted); text-decoration: underline; }

hr { border: none; border-top: 1px solid var(--line); margin: 2rem 0; }

p { margin: 0 0 1rem; font-size: 1.15rem; max-width: 72ch; }

a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  transition: color 140ms ease, border-color 140ms ease;
  text-underline-offset: 3px;
}
a:hover, a:focus-visible { border-bottom-color: currentColor; outline: none; }

/* ---------- Theme toggle ---------- */
.toggle {
  position: fixed; top: 1rem; right: 1rem; z-index: 30;
  background: color-mix(in oklab, var(--bg) 75%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  -webkit-backdrop-filter: saturate(1.2) blur(8px);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .45rem .65rem;
  font-size: .9rem;
  cursor: pointer;
}
.toggle:hover, .toggle:focus-visible { border-color: currentColor; outline: none; }

/* ---------- Wandering links (desktop) ---------- */
.floatingLink {
  position: absolute;
  font-weight: 500;
  border-bottom: none;
  color: var(--muted);
  text-transform: lowercase;
  transition: color 0.2s ease, opacity 0.4s ease, transform 0.15s ease;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  padding: .25rem .4rem;
}
.floatingLink.ready { opacity: 1; pointer-events: auto; }
.floatingLink:hover, .floatingLink:focus-visible { transform: translateY(-2px); outline: none; }

/* ---------- Bottom link rail (mobile) ---------- */
#linkRail {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem clamp(.5rem, 4vw, 1rem);
  padding-bottom: calc(.5rem + env(safe-area-inset-bottom));
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;

  background: color-mix(in oklab, var(--bg) 75%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  -webkit-backdrop-filter: saturate(1.2) blur(8px);

  border-top: 1px solid var(--line);
}

/* Chip styling inside the rail */
#linkRail .floatingLink {
  position: static;
  opacity: 1;
  pointer-events: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .45rem .7rem;
  margin: 0;
  white-space: nowrap;
  font-size: 1rem;
  scroll-snap-align: start;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(6px);
  -webkit-backdrop-filter: saturate(1.1) blur(6px);
}

/* Give space so the fixed rail doesn't cover content */
body.rail-active { padding-bottom: 4.5rem; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .floatingLink { transition: none; }
  #linkRail { scroll-behavior: auto; }
}

/* ---------- CV: unified spacing & typography ---------- */
.section-title { margin: 2.25rem 0 1rem; font-size: 1.65rem; font-weight: 600; text-transform: lowercase; }
.org-block { margin: 1rem 0 1.25rem; }
.section-title + .org-block { margin-top: 0.25rem; }
.org-name { font-weight: 600; margin: 0 0 .35rem; }
.role-list { list-style: none; margin: 0; padding: 0; }
.role-item {
  display: grid; grid-template-columns: 1fr auto;
  gap: .35rem 1rem; padding: .25rem 0; align-items: baseline;
}
.dates { color: var(--muted); font-size: .95rem; white-space: nowrap; }

@media (max-width: 720px) {
  .role-item { grid-template-columns: 1fr; gap: .15rem; }
  .dates { order: 3; }
}

.wrap > *:not(h1):not(hr) { max-width: 72ch; }

@media (max-width: 720px) {
  .section-title { font-size: 1.5rem; margin-top: 2rem; }
  p { font-size: 1.05rem; line-height: 1.6; }
  .role-item { grid-template-columns: 1fr; gap: 0.1rem; padding: 0.15rem 0; }
  .org-name { font-size: 1.1rem; }
  .dates { font-size: 0.95rem; }
  .edu-line { display: block; margin: 0 0 0.35rem; }
}

/* ---------- Fallback for browsers without backdrop-filter ---------- */
@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  #linkRail { background: var(--bg); }
  .toggle   { background: var(--bg); }
}

@supports not (background: color-mix(in oklab, white 75%, transparent)) {
  #linkRail, .toggle { background: var(--bg); }
}

a.no-underline {
  border-bottom: none !important;
  text-decoration: none !important;
}