:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --fg: #0a0a0a;
  --muted: #5a5852;
  --rule: #d8d3c5;
  --link-underline: #b8ad94;
  --accent: #7a2e1f;
}
html[data-theme="dark"] {
  --bg: #16171a;
  --surface: #1e1f23;
  --fg: #f1ede4;
  --muted: #a8a298;
  --rule: #34343a;
  --link-underline: #5e5648;
  --accent: #e6a591;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
html { transition: background-color 0.25s ease, color 0.25s ease; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 20px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 64px 32px 96px; position: relative; }

/* Theme toggle */
.theme-toggle {
  position: absolute; top: 28px; right: 32px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1.5px solid var(--rule); background: transparent;
  color: var(--muted); cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--fg);
  background: var(--surface);
}
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle .sun { display: none; }
html[data-theme="dark"] .theme-toggle .moon { display: none; }
html[data-theme="dark"] .theme-toggle .sun { display: block; }

/* Header */
header { display: flex; gap: 36px; align-items: center; margin-bottom: 8px; }
header img {
  width: 172px; height: 172px; object-fit: cover; border-radius: 6px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 14px rgba(0,0,0,0.04);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
header img:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06), 0 10px 28px rgba(0,0,0,0.10);
}
header .bio h1 {
  font-size: 40px; font-weight: 600; margin: 0 0 18px 0;
  letter-spacing: -0.02em; line-height: 1.05;
}
header .bio p { margin: 0 0 14px 0; font-size: 20px; line-height: 1.55; }
header .bio .links {
  margin-top: 22px; display: flex; gap: 6px; flex-wrap: wrap;
}
header .bio .links a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 8px;
  color: var(--muted); text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}
header .bio .links a:hover {
  color: var(--accent); background: var(--surface);
}
header .bio .links svg { width: 20px; height: 20px; display: block; }

/* Sections */
h2 {
  font-size: 13px; font-weight: 700;
  margin: 64px 0 22px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  display: flex; align-items: center; gap: 12px;
}
h2::before {
  content: ""; display: inline-block;
  width: 18px; height: 2px; background: var(--accent);
  border-radius: 1px; flex-shrink: 0;
}
p { margin: 0 0 16px; }
a {
  color: var(--fg); text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--link-underline);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
a:hover { text-decoration-color: var(--accent); color: var(--accent); }

/* Work entries */
.entry { margin: 0 0 32px; }
.entry .head { margin: 0 0 10px; }
.entry .org { font-weight: 600; }
.entry .role { color: var(--muted); }
.entry .when {
  float: right; color: var(--muted); font-size: 16px;
  font-variant-numeric: tabular-nums; padding-top: 4px;
}
.entry p { margin: 0; }

/* Plain lists */
ul.refs { list-style: none; padding: 0; margin: 0; }
ul.refs li { margin: 0 0 14px; padding-left: 36px; text-indent: -36px; line-height: 1.5; }
ul.refs li .idx {
  display: inline-block; width: 28px; color: var(--muted); font-size: 16px;
  text-indent: 0;
}
ul.refs li .meta { color: var(--muted); font-size: 16px; }

/* Contact */
form { display: grid; gap: 12px; margin-top: 16px; max-width: 540px; }
input, textarea {
  font: inherit; font-size: 18px; padding: 11px 14px;
  border: 1px solid var(--rule); border-radius: 3px;
  background: var(--surface); color: var(--fg); width: 100%;
}
textarea { min-height: 130px; resize: vertical; }
button {
  font: inherit; font-size: 17px; padding: 11px 22px; font-weight: 500;
  border: 1.5px solid var(--fg); background: transparent; color: var(--fg);
  border-radius: 3px; cursor: pointer; justify-self: start;
  display: inline-flex; align-items: center; gap: 10px;
  transition: background 0.15s ease, color 0.15s ease;
}
button:hover { background: var(--fg); color: var(--bg); }
form button svg { width: 16px; height: 16px; transition: transform 0.2s ease; }
form button:hover svg { transform: translateX(3px); }

/* Focus + motion accessibility */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, .theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Photo gallery */
.gallery {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
  margin: 8px 0 20px;
}
.gallery figure { margin: 0; position: relative; overflow: hidden; border-radius: 4px; }
.gallery img {
  width: 100%; height: 240px; object-fit: cover; display: block;
  transition: transform 0.4s ease, filter 0.3s ease;
  filter: saturate(0.92);
}
.gallery figure:hover img { transform: scale(1.04); filter: saturate(1.05); }

/* Selected writing list */
ul.essays { list-style: none; padding: 0; margin: 8px 0 18px; }
ul.essays li {
  display: flex; gap: 18px; margin: 0 0 10px;
  align-items: baseline;
}
ul.essays li .year {
  flex: 0 0 48px; color: var(--muted); font-size: 15px;
  font-variant-numeric: tabular-nums;
}
ul.essays li a {
  color: var(--fg); text-decoration: none;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
ul.essays li a:hover {
  color: var(--accent); border-bottom-color: var(--accent);
}
.archive-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 4px; font-size: 16px; color: var(--muted);
  text-decoration: none; border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.archive-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
.archive-link svg { width: 14px; height: 14px; }

/* Inline future-note (small muted) */
.note { color: var(--muted); font-size: 17px; }

footer {
  margin-top: 80px; color: var(--muted); font-size: 14px;
}

/* ------ Blog post pages ------ */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 15px; text-decoration: none;
  border-bottom: none;
  margin-bottom: 40px;
}
.back-link:hover { color: var(--accent); }
.back-link svg { width: 14px; height: 14px; transition: transform 0.2s ease; }
.back-link:hover svg { transform: translateX(-3px); }

.post-meta {
  color: var(--muted); font-size: 15px; margin: 0 0 32px;
  font-variant-numeric: tabular-nums;
}

.prose h1 {
  font-size: 36px; font-weight: 600; margin: 0 0 12px;
  letter-spacing: -0.02em; line-height: 1.2;
}
.prose h2 {
  font-size: 22px; font-weight: 600; margin: 40px 0 14px;
  color: var(--fg); text-transform: none; letter-spacing: -0.01em;
  display: block;
}
.prose h2::before { content: none; }
.prose h3 {
  font-size: 18px; font-weight: 600; margin: 32px 0 12px;
  color: var(--fg); letter-spacing: -0.005em;
}
.prose h4 { font-size: 17px; font-weight: 600; margin: 24px 0 10px; }
.prose p { font-size: 19px; line-height: 1.7; margin: 0 0 18px; }
.prose ul, .prose ol { padding-left: 24px; margin: 0 0 18px; }
.prose li { margin: 0 0 8px; line-height: 1.65; }
.prose blockquote {
  margin: 20px 0; padding: 4px 0 4px 20px;
  border-left: 3px solid var(--accent);
  color: var(--muted); font-style: italic;
}
.prose hr {
  border: none; border-top: 1px solid var(--rule);
  margin: 40px 0;
}
.prose code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em; padding: 2px 6px; border-radius: 3px;
  background: var(--surface); border: 1px solid var(--rule);
}
.prose pre {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: 4px; padding: 16px 18px; overflow-x: auto;
  font-size: 15px; line-height: 1.5;
}
.prose pre code { padding: 0; border: none; background: transparent; }
.prose img {
  max-width: 100%; height: auto; border-radius: 4px;
  margin: 20px 0;
}
.prose a {
  color: var(--fg); text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 3px;
}
.prose a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* Audio / media callout */
.audio-note {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; margin: 16px 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  color: var(--muted);
  font-size: 15.5px;
  font-style: italic;
}
.audio-note svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--accent); }
.audio-note a {
  color: var(--fg); text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 3px;
}
.audio-note a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* Blog index listing */
.post-index {
  list-style: none; padding: 0; margin: 0;
}
.post-index li {
  display: flex; gap: 20px; padding: 14px 0;
  border-bottom: 1px solid var(--rule);
  align-items: baseline;
}
.post-index li:last-child { border-bottom: none; }
.post-index .date {
  flex: 0 0 110px; color: var(--muted); font-size: 14.5px;
  font-variant-numeric: tabular-nums;
}
.post-index a {
  color: var(--fg); text-decoration: none; line-height: 1.45;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.post-index a:hover {
  color: var(--accent); border-bottom-color: var(--accent);
}

@media (max-width: 640px) {
  body { font-size: 19px; }
  .wrap { padding: 56px 22px 72px; }
  .theme-toggle { top: 20px; right: 22px; }
  header { flex-direction: column; gap: 22px; align-items: flex-start; }
  header img { width: 140px; height: 140px; }
  header .bio h1 { font-size: 34px; }
  header .bio p { font-size: 19px; }
  .entry .when { float: none; display: block; padding-top: 0; margin-bottom: 4px; }
  .entry .head { margin-bottom: 10px; }
  .gallery { grid-template-columns: 1fr 1fr; gap: 6px; }
  .gallery figure:first-child { grid-column: 1 / -1; }
  .gallery img { height: 200px; }
  .gallery figure:first-child img { height: 240px; }
  .prose h1 { font-size: 30px; }
  .prose p { font-size: 18px; }
  .post-index li { flex-direction: column; gap: 4px; padding: 12px 0; }
  .post-index .date { flex-basis: auto; }
}
