*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #ffffff;
  --text: #000000;
  --muted: #666666;
  --border: #eeeeee;
  --header-bg: transparent;
  --blue: #3d9eff;
  --link: #3d9eff;
  --link-hover: #2b8cef;
  --selection-bg: #3d9eff;
  --selection-text: #ffffff;
  --font: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --max-width: 44rem;
  --header-height: 3.25rem;
  --section-gap: 2.5rem;
  --pad-inline: clamp(1rem, 4vw, 1.5rem);
  --pad-block: clamp(1.5rem, 4vh, 2.75rem);
  --focus-ring: 2px solid var(--blue);
  --focus-offset: 3px;
}

html[data-theme="dark"] {
  --bg: #000000;
  --text: #ffffff;
  --muted: #999999;
  --border: #222222;
  --header-bg: transparent;
  --blue: #5eb0ff;
  --link: #5eb0ff;
  --link-hover: #8ec8ff;
  --selection-bg: #3d9eff;
  --selection-text: #ffffff;
}

html {
  font-size: 16px;
  scroll-padding-top: calc(var(--header-height) + 0.75rem);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.65;
  overflow-x: clip;
  overflow-wrap: break-word;
}

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

::selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

::-moz-selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.site-header {
  min-height: var(--header-height);
  background: var(--header-bg);
  isolation: isolate;
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: var(--header-height);
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 max(var(--pad-inline), env(safe-area-inset-right, 0px))
    0 max(var(--pad-inline), env(safe-area-inset-left, 0px));
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.35rem;
  min-width: 0;
  font-size: 0.9375rem;
  line-height: 1.2;
}

.site-nav a {
  display: inline-block;
  padding: 0.45rem 0.5rem;
  color: var(--text);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--link);
}

.site-nav a.is-active {
  font-weight: 600;
  color: var(--link);
}

.theme-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 0 0.15rem;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 0;
  vertical-align: middle;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  color: var(--link);
}

.theme-toggle svg {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
}

.theme-toggle .icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

body {
  padding-top: 0;
}

body.home .page.home {
  padding-top: clamp(0.75rem, 2vh, 1.25rem);
}

body.home .home-hero {
  margin-bottom: 1.25rem;
}

.home-bio-lead {
  margin: 0 0 0.65rem;
  font-size: clamp(1.5rem, 5vw, 2rem);
  line-height: 1.2;
}

.home-bio-lead strong {
  font-weight: 700;
}

.home-bio {
  margin: 0 0 1.35rem;
  font-size: 0.9375rem;
  line-height: 1.75;
  max-width: 34.5rem;
  color: var(--text);
}

.home-bio:last-of-type {
  margin-bottom: 0.5rem;
}

.home-bio a,
.page-intro a {
  color: var(--link);
  text-decoration: none;
}

.home-bio a:hover,
.page-intro a:hover {
  text-decoration: underline;
}

.home-refs {
  margin-top: 1.65rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.home-refs .home-see-more {
  margin: 0;
}

.home-refs .home-see-more + .home-see-more {
  margin-top: 0.5rem;
}

.home-copy {
  min-width: 0;
}

.page-intro {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--muted);
}

.section-note {
  margin: -0.15rem 0 0.65rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted);
}

.home-see-more {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted);
}

.page-see-more {
  margin: 1.5rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted);
}

.page-see-more a,
.home-see-more a {
  color: var(--link);
  font-weight: 500;
  text-decoration: none;
}

.page-see-more a:hover,
.home-see-more a:hover {
  text-decoration: underline;
}

.home-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0;
  margin: 1.25rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 500;
}

.home-links a {
  display: inline-block;
  padding: 0.15rem 0;
  color: var(--link);
  text-decoration: none;
}

.home-links a:not(:last-child)::after {
  content: "·";
  margin-left: 0.85rem;
  color: var(--border);
  font-weight: 400;
  pointer-events: none;
}

.home-links a:hover {
  text-decoration: underline;
}

.avatar-wrap {
  width: 8.75rem;
  height: 8.75rem;
  flex-shrink: 0;
  justify-self: end;
  align-self: start;
  margin-top: 0.15rem;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
}

.avatar {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 38%;
  transform: scale(1.06);
}

.page {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: var(--pad-block) var(--pad-inline)
    max(2rem, env(safe-area-inset-bottom, 0px) + 1.25rem);
  padding-left: max(var(--pad-inline), env(safe-area-inset-left, 0px));
  padding-right: max(var(--pad-inline), env(safe-area-inset-right, 0px));
}

.page-title {
  margin: 0 0 1.25rem;
  font-size: clamp(1.65rem, 3.5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.section-title {
  margin: 0 0 0.35rem;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.content-section + .content-section,
.block + .block {
  margin-top: var(--section-gap);
}

.content-section--first {
  margin-top: 0;
}

.page-intro--flush {
  margin-bottom: 0;
}

.lead {
  margin: 0 0 1.5rem;
  font-size: 1rem;
  line-height: 1.7;
}

.lead a {
  color: var(--link);
  text-decoration: none;
}

.lead a:hover {
  text-decoration: underline;
}

.block p {
  margin: 0 0 1rem;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--muted);
}

.subhead-plain {
  margin: 1.5rem 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.block p a {
  color: var(--link);
  text-decoration: none;
}

.block p a:hover {
  text-decoration: underline;
}

/* Click-to-expand lists (Work, Research, Projects) */
.fold-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.fold-list > li {
  border-bottom: 1px solid var(--border);
}

.fold-list > li:first-child {
  border-top: 1px solid var(--border);
}

.fold {
  width: 100%;
}

.fold__summary {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.6rem 0;
  cursor: pointer;
  list-style: none;
}

.fold__summary::-webkit-details-marker {
  display: none;
}

.fold__chevron {
  flex-shrink: 0;
  width: 0.85rem;
  margin-top: 0.2rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.fold[open] .fold__chevron {
  transform: rotate(90deg);
}

.fold__main {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  min-width: 0;
}

.fold__title {
  font-weight: 500;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--text);
  overflow-wrap: anywhere;
}

.fold__at {
  color: var(--link);
}

.fold__title a {
  color: var(--link);
  text-decoration: none;
}

.fold__title a:hover {
  text-decoration: underline;
}

.fold__external {
  margin-left: 0.15rem;
  font-size: 0.85em;
  color: var(--link);
}

.fold__date {
  flex-shrink: 0;
  max-width: 48%;
  font-size: 0.8125rem;
  line-height: 1.4;
  text-align: right;
  color: var(--muted);
}

.fold__panel {
  padding: 0 0 0.75rem 1.2rem;
}

.fold__lead {
  margin: 0 0 0.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
}

.fold__meta {
  margin: 0 0 0.25rem;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--muted);
}

.fold__tags {
  margin: 0 0 0.35rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.fold__desc {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--muted);
}

.fold__desc a {
  color: var(--link);
  text-decoration: underline;
}

.skills {
  margin: 0;
}

.skills > div {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.skills > div:first-child {
  border-top: 1px solid var(--border);
}

.skills dt {
  margin: 0 0 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--link);
}

.skills dd {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--muted);
}

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

.list-plain li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--muted);
}

.list-plain li:first-child {
  border-top: 1px solid var(--border);
}

.list-plain strong {
  color: var(--text);
  font-weight: 600;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.site-footer {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  text-align: center;
}

.social-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.social-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  color: var(--muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.social-links a:hover {
  color: var(--link);
  text-decoration: none;
}

.social-links svg {
  width: 1.25rem;
  height: 1.25rem;
}

.footer-copy,
.footer p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.quote {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  font-style: italic;
  color: var(--muted);
  line-height: 1.6;
}

/* Tablet: stack home before it gets cramped */
@media (max-width: 52rem) {
  body.home .home-grid {
    display: block;
  }

  .avatar-wrap {
    float: right;
    width: 7rem;
    height: 7rem;
    margin: 0.25rem 0 0.75rem 1.25rem;
    shape-outside: circle();
  }

  body.home .home-links {
    clear: both;
  }
}

/* Small tablet / large phone */
@media (max-width: 40rem) {
  :root {
    --header-height: 3.5rem;
    --section-gap: 2rem;
  }

  .fold__main {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .fold__date {
    max-width: 100%;
    text-align: left;
  }

  .fold__panel {
    padding-left: 1rem;
    padding-right: 0;
  }

  .page-title {
    font-size: clamp(1.5rem, 6vw, 1.85rem);
  }
}

/* Phone */
@media (max-width: 30rem) {
  :root {
    --pad-inline: max(1rem, env(safe-area-inset-left, 0px));
    --section-gap: 1.75rem;
  }

  .site-nav {
    gap: 0.3rem 0.2rem;
    font-size: 0.8125rem;
  }

  .site-nav a {
    padding-inline: 0.4rem;
  }

  .theme-toggle {
    width: 2.75rem;
    height: 2.75rem;
    margin-left: 0.1rem;
    padding: 0;
  }

  .home-bio-lead {
    font-size: clamp(1.375rem, 6vw, 1.75rem);
  }

  .home-bio,
  .home-links {
    font-size: 0.9375rem;
  }

  .avatar-wrap {
    width: 5.75rem;
    height: 5.75rem;
    margin: 0.15rem 0 0.5rem 1rem;
  }

  .avatar {
    object-position: 50% 36%;
    transform: scale(1.04);
  }

  .fold__summary {
    padding: 0.75rem 0;
  }

  .site-footer {
    margin-top: 2.25rem;
    padding-top: 1.5rem;
  }

  .social-links {
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
  }
}

/* Very narrow (e.g. iPhone SE, folded phones) */
@media (max-width: 22.5rem) {
  :root {
    --header-height: 4.75rem;
  }

  .site-nav {
    font-size: 0.75rem;
    gap: 0.25rem 0.55rem;
  }

  .home-links {
    gap: 0.4rem 0.65rem;
    font-size: 0.875rem;
  }

  .fold__title {
    font-size: 0.9375rem;
  }

  .fold__date {
    font-size: 0.8125rem;
  }
}

/* Tablet landscape / small laptops */
@media (min-width: 30rem) and (max-width: 52rem) {
  .page {
    padding-inline: max(1.25rem, env(safe-area-inset-left, 0px))
      max(1.25rem, env(safe-area-inset-right, 0px));
  }
}

/* Large screens: comfortable reading width, no edge-to-edge stretch */
@media (min-width: 75rem) {
  :root {
    --pad-inline: 1.5rem;
  }
}

/* Short viewports (landscape phones) */
@media (max-height: 32rem) and (orientation: landscape) {
  body.home .page.home {
    padding-top: 1rem;
    padding-bottom: 1rem;
  }

  body.home .home-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1.5rem 2rem;
    align-items: start;
  }

  .avatar-wrap {
    float: none;
    width: 5.5rem;
    height: 5.5rem;
    margin: 0;
    justify-self: end;
    shape-outside: none;
  }
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #000000;
    --text: #ffffff;
    --muted: #999999;
    --border: #222222;
    --header-bg: transparent;
    --blue: #5eb0ff;
    --link: #5eb0ff;
    --link-hover: #8ec8ff;
    --selection-bg: #3d9eff;
    --selection-text: #ffffff;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
