/* ---------------------------------------------------------------------------
   Tokens
   Light is the default; dark comes from prefers-color-scheme. Both palettes
   are warm-neutral greys with a single accent, so code blocks carry the color.
   --------------------------------------------------------------------------- */

:root {
  --bg: #fafaf9;
  --bg-subtle: #f2f1ef;
  --text: #1c1b1a;
  --text-muted: #6b6862;
  --rule: #e2e0dc;
  --accent: #7166a9;
  --code-bg: #f2f1ef;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.06);

  --measure: 68ch;
  --gap: clamp(2rem, 5vw, 4rem);
  --pad-inline: clamp(1.25rem, 5vw, 2rem);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --bg-subtle: #1a1a19;
    --text: #e8e6e3;
    --text-muted: #9a9791;
    --rule: #2a2a28;
    --accent: #9b90d0;
    --code-bg: #17171a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
  }
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  /* 16px floor keeps iOS Safari from zooming on focus. */
  font: 400 1rem/1.65 var(--font-sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* Long URLs in prose must not push the layout wider than the viewport. */
  overflow-wrap: break-word;
  /* Respect the notch on iOS while keeping a sane floor elsewhere. */
  padding-inline: max(var(--pad-inline), env(safe-area-inset-left));
}

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

a {
  color: inherit;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.2em;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 10;
  padding: 0.75rem 1rem;
  color: var(--bg);
  background: var(--text);
  border-radius: 6px;
  text-decoration: none;
}

/* ---------------------------------------------------------------------------
   Masthead — name, social icons, nav. Centered, generous, low contrast.
   --------------------------------------------------------------------------- */

.masthead {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  max-width: 72rem;
  margin: 0 auto;
  padding-block: clamp(2rem, 6vw, 3rem) clamp(2.5rem, 6vw, 4rem);
  text-align: center;
}

.masthead__name {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-transform: lowercase;
}

.masthead__name a {
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.masthead__name a:hover {
  color: inherit;
  opacity: 0.6;
}

.social {
  display: flex;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.social__link {
  display: grid;
  place-items: center;
  /* 44px hit area on touch, per WCAG 2.5.5 / Apple HIG, without a 44px icon. */
  width: 44px;
  height: 44px;
  color: var(--text-muted);
  border-radius: 8px;
}

.social__link:hover {
  color: var(--accent);
}

.nav ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav a {
  display: inline-block;
  /* Padding gets these to 44px tall without inflating the visual type size. */
  padding: 0.75rem 0.25rem;
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text-muted);
}

.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--text);
}

.nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.4em;
}

/* ---------------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------------- */

.main {
  max-width: 72rem;
  margin: 0 auto;
}

.split {
  display: grid;
  gap: var(--gap);
  padding-bottom: 4rem;
}

/* Single column until there is genuinely room for two readable ones.
   Below this the portrait is hidden entirely so prose gets the full width. */
@media (min-width: 62rem) {
  .split:not(.split--solo) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 22rem);
    align-items: start;
  }
}

.split__aside {
  display: none;
}

@media (min-width: 62rem) {
  .split__aside {
    display: block;
    position: sticky;
    top: 2rem;
  }
}

.portrait {
  display: block;
  width: 100%;
  border-radius: 16px;
  box-shadow: var(--shadow);
  object-fit: cover;
}

.footer {
  max-width: 72rem;
  margin: 0 auto;
  padding-block: 2rem;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.footer p {
  margin: 0;
}

/* ---------------------------------------------------------------------------
   Prose
   --------------------------------------------------------------------------- */

.prose {
  max-width: var(--measure);
  font-size: 0.9375rem;
}

/* Interior pages share the home page's left edge rather than centering, so the
   heading, entries, and footer rule all line up on one axis. */
.prose--narrow {
  margin-inline: 0;
  padding-bottom: 4rem;
}

.prose > :first-child {
  margin-top: 0;
}

/* Scoped so `.prose p` does not win on specificity and reset the margin. */
.prose .lede {
  margin-bottom: 1.5rem;
  font-size: clamp(1.3rem, 4vw, 1.5rem);
  line-height: 1.25;
  font-weight: 400;
  letter-spacing: -0.015em;
}

.prose h1,
.prose h2,
.prose h3 {
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.prose h1 {
  font-size: 1.75rem;
}

.prose h2 {
  font-size: 1.25rem;
}

.prose h3 {
  font-size: 1.0625rem;
}

.prose p,
.prose ul,
.prose ol {
  margin-block: 0 1.15rem;
}

.prose ul,
.prose ol {
  padding-left: 1.25rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose li::marker {
  color: var(--text-muted);
}

/* Links carry their own underline in the accent so they read as links at rest,
   not just on hover. --rule was too close to the background to be visible. */
.prose a {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.prose a:hover {
  color: var(--accent);
  text-decoration-thickness: 2px;
}

.prose blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--text-muted);
}

.prose hr {
  height: 1px;
  margin: 2.5rem 0;
  background: var(--rule);
  border: 0;
}

.prose img {
  border-radius: 8px;
  border: 1px solid var(--rule);
}

/* Code ---------------------------------------------------------------------- */

.prose code {
  padding: 0.15em 0.35em;
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border-radius: 4px;
}

.prose pre {
  margin-block: 0 1.25rem;
  padding: 1rem;
  /* Wide code must scroll inside its box, never widen the page. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
}

.prose pre code {
  padding: 0;
  font-size: inherit;
  background: none;
  border-radius: 0;
  white-space: pre;
}

.prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}

.prose th,
.prose td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule);
  text-align: left;
}

/* ---------------------------------------------------------------------------
   Research listing
   --------------------------------------------------------------------------- */

/* Scoped to beat `.prose ul`, which would otherwise indent the list and knock
   the entries out of alignment with the page heading. */
.prose .entries {
  margin: 2rem 0 0;
  padding-left: 0;
  list-style: none;
}

.entry {
  display: grid;
  gap: 0.25rem 1.5rem;
  padding-block: 1.5rem;
  border-top: 1px solid var(--rule);
}

@media (min-width: 40rem) {
  .entry {
    grid-template-columns: 6.5rem minmax(0, 1fr);
  }
}

.entry__date {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding-top: 0.2rem;
}

.prose .entry__title {
  margin: 0 0 0.35rem;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.35;
}

.entry__title a {
  text-decoration: none;
}

.entry__excerpt {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.post-header {
  margin-bottom: 2rem;
}

.post-header h1 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.post-meta {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.post-back {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
}

.post-back a {
  text-decoration: none;
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
