:root {
  color-scheme: light;

  --bg: #fbfaf7;
  --bg-soft: #f3f1ec;
  --text: #18202e;
  --text-muted: #3d4859;
  --text-subtle: #5c6779;
  --line: #e5e1d8;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;

  --font-heading: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 72px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, ul { margin: 0; }
ul, ol { padding: 0; margin: 0; list-style: none; }
img { max-width: 100%; }
button { font: inherit; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
[hidden] { display: none !important; }
::selection { background: #cfe0ff; }

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

.skip-link {
  position: absolute; left: 16px; top: -48px; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 4px;
}
.skip-link:focus { top: 12px; color: #fff; }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 24px; }
section { padding: 72px 0; }

h2.section-title {
  font-family: var(--font-heading); font-weight: 600; font-size: 28px;
  margin-bottom: 32px;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(251, 250, 247, 0.94);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 860px; height: 60px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.wordmark {
  font-family: var(--font-heading); font-weight: 600; font-size: 18px;
  color: var(--text); text-decoration: none;
}
.mainnav { display: flex; align-items: center; gap: 24px; font-size: 15px; }
.mainnav a { color: var(--text-muted); text-decoration: none; }
.mainnav a:hover { color: var(--accent); }

.btn {
  display: inline-block; padding: 9px 18px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--accent); font-size: 15px; text-decoration: none;
  background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-secondary { background: transparent; color: var(--accent); }
.btn-secondary:hover { background: var(--bg-soft); color: var(--accent-hover); }

.hero { padding: 64px 0 56px; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 48px; align-items: center; }
.hero h1 { font-family: var(--font-heading); font-weight: 600; font-size: 44px; line-height: 1.15; margin-bottom: 6px; }
.hero-role { font-size: 18px; color: var(--text-subtle); margin-bottom: 20px; }
.hero-bio { max-width: 56ch; color: var(--text-muted); margin-bottom: 28px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.portrait { display: block; width: 190px; height: 190px; object-fit: cover; object-position: 50% 25%; border-radius: 8px; }

.about { background: var(--bg-soft); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.about-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 56px; }
.about p { color: var(--text-muted); margin-bottom: 14px; }
.about p:last-child { margin-bottom: 0; }
.credlist { padding-top: 62px; }
.credlist li { padding: 12px 0; border-top: 1px solid var(--line); }
.credlist li:first-child { border-top: 0; padding-top: 0; }
.cred-role { font-weight: 600; font-size: 15px; }
.cred-meta { font-size: 14px; color: var(--text-subtle); }

.project { padding: 32px 0; border-top: 1px solid var(--line); }
.project:first-of-type { border-top: 0; padding-top: 0; }
.project h3 { font-family: var(--font-heading); font-weight: 600; font-size: 22px; }
.project-meta { font-size: 14px; color: var(--text-subtle); margin: 2px 0 12px; }
.project-desc { max-width: 66ch; color: var(--text-muted); margin-bottom: 14px; }
.facts { margin-bottom: 14px; padding-left: 18px; list-style: disc; color: var(--text-muted); font-size: 15px; }
.facts li { margin-bottom: 4px; }
.facts strong { color: var(--text); font-weight: 600; }
.stack { font-size: 14px; color: var(--text-subtle); margin-bottom: 10px; }
.project-links { font-size: 15px; display: flex; gap: 18px; }

.path-wrap { margin-top: 56px; }
.path-title { font-family: var(--font-heading); font-weight: 600; font-size: 20px; margin-bottom: 8px; }
.path { position: relative; height: 270px; }
.path-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.path-line .flow { fill: none; stroke: var(--accent); stroke-width: 2; }
.path li { position: absolute; left: var(--x); top: var(--y); width: 13%; font-size: 14px; line-height: 1.4; }
.path .dot { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.path .txt { display: block; margin: 12px 0 0 -5px; color: var(--text); }
.path strong { display: block; font-size: 13px; color: var(--accent); }
.path .sub { color: var(--text-subtle); font-size: 13px; }

.lessons { background: var(--bg-soft); border-top: 1px solid var(--line); }
.lessons-intro { color: var(--text-muted); margin: -16px 0 28px; }
.lesson { padding: 20px 0; border-top: 1px solid var(--line); max-width: 66ch; }
.lesson:first-of-type { border-top: 0; padding-top: 0; }
.lesson h3 { font-family: var(--font-heading); font-weight: 600; font-size: 19px; }
.lesson-where { font-size: 14px; color: var(--accent); margin: 1px 0 6px; }
.lesson p:last-child { color: var(--text-muted); }

.diagram { margin: 4px 0 18px; overflow-x: auto; }
.diagram svg { display: block; width: 100%; min-width: 560px; max-width: 640px; height: auto; }
.diagram .box rect { fill: var(--bg); stroke: var(--accent); stroke-width: 1.5; }
.diagram text { font-family: var(--font-body); font-size: 13.5px; fill: var(--text); text-anchor: middle; }
.diagram .sub { font-size: 11.5px; fill: var(--text-subtle); }
.diagram .note { font-size: 12px; fill: var(--text-subtle); }
.diagram .flow { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.diagram .head { fill: var(--accent); }

.js .reveal { opacity: 0; transform: translateY(14px); }
.js .reveal.in { opacity: 1; transform: none; transition: opacity 0.6s ease, transform 0.6s ease; }
.js .diagram .box, .js .diagram .head, .js .path li { opacity: 0; }
.js .diagram .flow, .js .path .flow { stroke-dasharray: 1; stroke-dashoffset: 1; }
.diagram.in .box { opacity: 1; transition: opacity 0.5s ease calc(var(--i, 0) * 0.12s); }
.diagram.in .head { opacity: 1; transition: opacity 0.3s ease calc(var(--i, 0) * 0.12s + 0.5s); }
.diagram.in .flow { stroke-dashoffset: 0; transition: stroke-dashoffset 0.7s ease calc(var(--i, 0) * 0.12s); }
.path.in .flow { stroke-dashoffset: 0; transition: stroke-dashoffset 1.6s ease; }
.path.in li { opacity: 1; transition: opacity 0.5s ease calc(var(--i, 0) * 0.28s + 0.2s); }

.contact { padding-bottom: 56px; }
.contact p { color: var(--text-muted); margin-bottom: 18px; max-width: 52ch; }
.contact-links li { margin-bottom: 6px; }

.footer { padding: 24px 0 40px; border-top: 1px solid var(--line); font-size: 14px; color: var(--text-subtle); }

.chat-fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 80;
  padding: 11px 18px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 15px;
  box-shadow: 0 2px 8px rgba(24, 32, 46, 0.25);
}
.chat-fab:hover { background: var(--accent-hover); }

.chat-panel {
  position: fixed; right: 20px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 80;
  display: flex; flex-direction: column; overflow: hidden;
  width: min(380px, calc(100vw - 40px)); height: min(540px, calc(100vh - 140px));
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(24, 32, 46, 0.18);
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-soft); border-bottom: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.chat-close {
  width: 28px; height: 28px; border: 0; border-radius: 4px; background: none; cursor: pointer;
  color: var(--text-subtle); font-size: 20px; line-height: 1;
}
.chat-close:hover { background: var(--line); color: var(--text); }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto; }
.msg { max-width: 90%; font-size: 15px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.visitor { align-self: flex-end; padding: 8px 12px; background: #e8effc; border-radius: 10px 10px 2px 10px; }
.msg.control { align-self: flex-start; color: var(--text-muted); }
.msg.control .tag { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 600; color: var(--accent); }
.msg.system { align-self: center; text-align: center; font-size: 14px; color: var(--text-subtle); }
.msg.pending { color: var(--text-subtle); }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; }
.chip {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: none; cursor: pointer;
  font-size: 13px; color: var(--text-muted);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chat-input-row { display: flex; border-top: 1px solid var(--line); }
.chat-input-row input {
  flex: 1; min-width: 0; padding: 12px 14px; border: 0; background: none; color: var(--text); font-size: 15px;
}
.chat-input-row input:focus-visible { outline-offset: -2px; }
.chat-send { padding: 0 18px; border: 0; background: none; cursor: pointer; color: var(--accent); font-size: 15px; font-weight: 600; }
.chat-send:disabled { color: var(--text-subtle); cursor: default; }

@media (max-width: 720px) {
  section { padding: 52px 0; }
  .hero { padding: 40px 0 44px; }
  .hero-grid { grid-template-columns: 1fr; gap: 24px; }
  .portrait { order: -1; width: 112px; height: 112px; }
  .hero h1 { font-size: 34px; }
  .mainnav a:not(.btn) { display: none; }
  .about-grid { grid-template-columns: 1fr; gap: 32px; }
  .credlist { padding-top: 0; }
  .chat-panel { left: 12px; right: 12px; width: auto; }
  .path { height: auto; }
  .path-line { display: none; }
  .path li { position: static; width: auto; margin: 0 0 14px; padding-left: 14px; border-left: 2px solid var(--accent); }
  .path .dot { display: none; }
  .path .txt { margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .reveal, .js .diagram .box, .js .diagram .head, .js .path li { opacity: 1; transform: none; }
  .js .diagram .flow, .js .path .flow { stroke-dashoffset: 0; }
  .reveal, .diagram *, .path * { transition: none !important; }
}
