/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Variables — Light theme (default) */
:root {
  --font-body: 'Georgia', 'Times New Roman', serif;
  --font-heading: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --color-bg: #fafaf9;
  --color-text: #1c1917;
  --color-muted: #78716c;
  --color-accent: #292524;
  --color-border: #d6d3d1;
  --color-link: #1c1917;
  --color-link-hover: #57534e;
  --color-code-bg: #f5f5f4;
  --color-card-bg: #ffffff;
  --color-card-shadow: rgba(0,0,0,0.06);
  --color-diagram-bg: transparent;
  --max-width: 680px;
}

/* Dark theme */
[data-theme="dark"] {
  --color-bg: #0f1117;
  --color-text: #e8e6e3;
  --color-muted: #9ca3af;
  --color-accent: #e8e6e3;
  --color-border: #2d3039;
  --color-link: #e8e6e3;
  --color-link-hover: #9ca3af;
  --color-code-bg: #1a1d24;
  --color-card-bg: #1a1d24;
  --color-card-shadow: rgba(0,0,0,0.3);
  --color-diagram-bg: transparent;
}

/* Base */
html { font-size: 18px; line-height: 1.7; background: var(--color-bg); transition: background 0.3s; }
body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
  transition: background 0.3s, color 0.3s;
}

/* Links */
a { color: var(--color-link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--color-link-hover); }

/* Header */
.site-header { margin-bottom: 3rem; padding-bottom: 1rem; border-bottom: 1px solid var(--color-border); }
.site-header nav { display: flex; justify-content: space-between; align-items: baseline; }
.site-title { font-family: var(--font-heading); font-weight: 600; font-size: 1.1rem; text-decoration: none; }
.nav-links { display: flex; gap: 1.5rem; align-items: baseline; }
.nav-links a { font-family: var(--font-heading); font-size: 0.85rem; color: var(--color-muted); text-decoration: none; }
.nav-links a:hover { color: var(--color-text); }

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem;
  color: var(--color-muted);
  transition: color 0.2s;
  line-height: 1;
}
.theme-toggle:hover { color: var(--color-text); }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }

/* Home */
.home { max-width: 960px; margin: 0 auto; }
.intro { margin-bottom: 3rem; }
.intro h1 { font-family: var(--font-heading); font-size: 2.2rem; font-weight: 700; margin-bottom: 0.3rem; }
.tagline { font-family: var(--font-heading); font-size: 1.1rem; color: var(--color-muted); margin-bottom: 1rem; }

/* Post list */
.post-list { list-style: none; }
.post-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--color-border); }
.post-list li:last-child { border-bottom: none; }
.post-list a { text-decoration: none; font-weight: 500; }
.post-list time { font-family: var(--font-heading); font-size: 0.8rem; color: var(--color-muted); white-space: nowrap; }
.list-subtitle { display: block; font-size: 0.85rem; color: var(--color-muted); }

/* Article */
.post-header { margin-bottom: 2.5rem; }
.post-header h1 { font-family: var(--font-heading); font-size: 2rem; font-weight: 700; line-height: 1.2; margin-bottom: 0.5rem; }
.subtitle { font-family: var(--font-heading); font-size: 1.1rem; color: var(--color-muted); margin-bottom: 0.5rem; }
.meta { font-family: var(--font-heading); font-size: 0.8rem; color: var(--color-muted); display: flex; gap: 1.5rem; }

/* Table of contents */
.toc { margin-bottom: 2.5rem; padding: 1.5rem; background: var(--color-code-bg); border-radius: 4px; }
.toc h2 { font-family: var(--font-heading); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted); margin-bottom: 0.75rem; }
.toc ul { list-style: none; padding-left: 0; }
.toc li { padding: 0.15rem 0; }
.toc a { font-family: var(--font-heading); font-size: 0.85rem; text-decoration: none; color: var(--color-muted); }
.toc a:hover { color: var(--color-text); }
.toc ul ul { padding-left: 1.2rem; }

/* Post content */
.post-content h2 { font-family: var(--font-heading); font-size: 1.5rem; font-weight: 700; margin: 2.5rem 0 1rem; }
.post-content h3 { font-family: var(--font-heading); font-size: 1.15rem; font-weight: 600; margin: 2rem 0 0.75rem; }
.post-content h4 { font-family: var(--font-heading); font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
.post-content p { margin-bottom: 1.2rem; }
.post-content ul, .post-content ol { margin-bottom: 1.2rem; padding-left: 1.5rem; }
.post-content li { margin-bottom: 0.4rem; }
.post-content blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: 1.2rem;
  margin: 1.5rem 0;
  color: var(--color-muted);
  font-style: italic;
}
.post-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}
.post-content pre {
  background: var(--color-code-bg);
  padding: 1.2rem;
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}
.post-content pre code { background: none; padding: 0; }
.post-content strong { font-weight: 700; }
.post-content em { font-style: italic; }
.post-content hr { border: none; border-top: 1px solid var(--color-border); margin: 2.5rem 0; }

/* Tables */
.post-content table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; font-size: 0.9rem; }
.post-content th, .post-content td { padding: 0.6rem 0.8rem; border: 1px solid var(--color-border); text-align: left; }
.post-content th { font-family: var(--font-heading); font-weight: 600; background: var(--color-code-bg); }

/* Diagrams */
.post-content img {
  max-width: 100%;
  height: auto;
}
.post-content img[src*="c4ail-whitepaper"],
.post-content img[src*="c4ail-labour"] {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
  margin: 0.5rem auto;
  border-radius: 8px;
  box-shadow: 0 2px 12px var(--color-card-shadow);
  cursor: zoom-in;
  transition: box-shadow 0.2s;
}

.post-content img[src*="c4ail-whitepaper"]:hover,
.post-content img[src*="c4ail-labour"]:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.post-content .diagram-link {
  text-align: center;
  margin-top: -0.3rem;
  margin-bottom: 1rem;
  font-family: var(--font-heading);
  font-size: 0.8rem;
}

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

.post-content .diagram-link a:hover {
  color: var(--color-text);
}

/* Footer */
.site-footer {
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--color-muted);
}

/* Hero */
.hero { display: flex; gap: 2.5rem; align-items: center; margin-bottom: 3rem; }
.hero-text { flex: 1; }
.hero-text h1 { font-family: var(--font-heading); font-size: 2.5rem; font-weight: 700; margin-bottom: 0.3rem; }
.hero-image { flex-shrink: 0; }
.hero-image img { width: 160px; height: auto; border-radius: 8px; }
.hero-links { display: flex; gap: 1.2rem; margin-top: 1rem; }
.hero-links a {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  color: var(--color-muted);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}
.hero-links a:hover { color: var(--color-text); border-color: var(--color-text); }

/* Roles */
.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; margin-bottom: 3rem; }
.role h3 { font-family: var(--font-heading); font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; }
.role p { font-size: 0.9rem; color: var(--color-muted); line-height: 1.6; }
a.role-link {
  display: block;
  text-decoration: none;
  color: var(--color-text);
  padding: 1.2rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
a.role-link:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 12px var(--color-card-shadow);
  color: var(--color-text);
  transform: translateY(-2px);
}
a.role-link:hover .role-arrow { opacity: 1; transform: translateX(3px); }
.role-arrow {
  opacity: 0.4;
  transition: opacity 0.2s, transform 0.2s;
  font-weight: 400;
}

/* Section headings */
.recent h2, .list-page h1 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* The Thread */
.the-thread { margin-bottom: 3rem; }
.the-thread h2 { font-family: var(--font-heading); font-size: 1.2rem; font-weight: 600; margin-bottom: 0.5rem; }
.the-thread p { font-size: 0.95rem; color: var(--color-muted); line-height: 1.7; margin-bottom: 0.8rem; }
.the-thread a { font-family: var(--font-heading); font-size: 0.9rem; }

/* Essential Reading */
.essential-reading { margin-bottom: 3rem; }
.essential-reading h2 { font-family: var(--font-heading); font-size: 1.2rem; font-weight: 600; margin-bottom: 0.3rem; }
.section-intro { font-size: 0.9rem; color: var(--color-muted); margin-bottom: 1.5rem; }
.featured-works { display: grid; gap: 1.2rem; }
.featured-work {
  display: block;
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--color-text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.featured-work:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px var(--color-card-shadow);
  color: var(--color-text);
}
.featured-work h3 { font-family: var(--font-heading); font-size: 1.15rem; font-weight: 700; margin-bottom: 0.2rem; }
.featured-subtitle { display: block; font-family: var(--font-heading); font-size: 0.85rem; color: var(--color-muted); margin-bottom: 0.8rem; }
.featured-work p { font-size: 0.88rem; color: var(--color-muted); line-height: 1.6; margin: 0; }

/* Profile pages */
.profile-header { margin-bottom: 1.5rem; }
.profile-header h1 { font-family: var(--font-heading); font-size: 2rem; font-weight: 700; margin-bottom: 0.3rem; }
.profile-subtitle { font-family: var(--font-heading); font-size: 1rem; color: var(--color-muted); }
.profile-content > p:first-of-type {
  font-size: 1.05rem;
  color: var(--color-muted);
  line-height: 1.7;
  margin-bottom: 2rem;
}
.profile-content > hr:first-of-type { display: none; }
.profile-content > h2 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 1rem 0;
  padding: 1.5rem 1.5rem 0 1.5rem;
}
.profile-section {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0 1.5rem 1.5rem 1.5rem;
  margin-bottom: 1.5rem;
  background: var(--color-card-bg);
}
.profile-content h3 { font-family: var(--font-heading); font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
.profile-content p { margin-bottom: 0.8rem; font-size: 0.92rem; line-height: 1.65; }
.profile-content ul, .profile-content ol { margin-bottom: 0.8rem; padding-left: 1.5rem; font-size: 0.92rem; }
.profile-content li { margin-bottom: 0.3rem; line-height: 1.6; }
.profile-content a { color: var(--color-link); }
.profile-content a:hover { color: var(--color-link-hover); }
.profile-content strong { font-weight: 600; }
.profile-content hr {
  border: none;
  margin: 0;
  padding: 0;
}
.profile-content table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.88rem; }
.profile-content th, .profile-content td { padding: 0.5rem 0.7rem; border: 1px solid var(--color-border); text-align: left; }
.profile-content th { font-family: var(--font-heading); font-weight: 600; background: var(--color-code-bg); }
.profile-content blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--color-muted);
  font-style: italic;
}

/* Video grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  margin-bottom: 1.2rem;
}
.video-embed {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 4px;
}
.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.video-title {
  font-family: var(--font-heading);
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: 0.4rem;
  line-height: 1.3;
}

/* Responsive */
@media (max-width: 600px) {
  html { font-size: 16px; }
  body { padding: 1rem; overflow-x: hidden; }
  .post-content { overflow-x: hidden; }
  .post-header h1 { font-size: 1.6rem; }
  .intro h1 { font-size: 1.8rem; }
  .post-list li { flex-direction: column; gap: 0.2rem; }
  .hero { flex-direction: column-reverse; text-align: center; }
  .hero-links { justify-content: center; }
  .hero-image img { width: 120px; }
  .post-content table { display: block; overflow-x: auto; }
  .roles { grid-template-columns: 1fr; }
  .video-grid { grid-template-columns: 1fr; }
}
