/* ---------------------------------------------------------------------------
   Design tokens
--------------------------------------------------------------------------- */
:root {
  /* type */
  --font-serif: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, Georgia, serif;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --step--1: clamp(0.83rem, 0.8rem + 0.15vw, 0.94rem);
  --step-0: clamp(1rem, 0.96rem + 0.22vw, 1.125rem);
  --step-1: clamp(1.2rem, 1.14rem + 0.31vw, 1.4rem);
  --step-2: clamp(1.44rem, 1.35rem + 0.45vw, 1.75rem);
  --step-3: clamp(1.73rem, 1.6rem + 0.65vw, 2.2rem);
  --step-4: clamp(2.07rem, 1.89rem + 0.93vw, 2.75rem);

  /* spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --space-6: 4rem;

  --measure: 65ch;
  --radius: 8px;

  /* light theme (default) */
  --bg: #ffffff;
  --bg-raised: #f7f8f9;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --accent: #45607a;
  --accent-soft: #eef2f6;
  --border: #e6e8eb;
  --code-bg: #f7f8f9;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05);
}

[data-theme='dark'] {
  --bg: #131417;
  --bg-raised: #1a1c20;
  --text: #e3e4e6;
  --text-muted: #9099a3;
  --accent: #9db4c8;
  --accent-soft: #1e252c;
  --border: #2a2d33;
  --code-bg: #1a1c20;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
}

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

html {
  color-scheme: light;
}

[data-theme='dark'] {
  color-scheme: dark;
}

@view-transition {
  navigation: auto;
}

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

h1,
h2,
h3,
h4 {
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
  text-wrap: balance;
  margin: 0 0 var(--space-3);
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }

p { margin: 0 0 var(--space-3); }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover { text-decoration-thickness: 2px; }

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

code,
pre {
  font-family: var(--font-mono);
  font-size: 0.88em;
}

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

/* ---------------------------------------------------------------------------
   Layout: header / main / footer
--------------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--border);
}

.site-nav {
  max-width: 72rem;
  margin-inline: auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-family: var(--font-sans);
}

.site-name {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  font-size: var(--step-0);
}

.site-links {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.site-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--step--1);
}

.site-links a:hover { color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
}

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

.icon-moon { display: none; }
[data-theme='dark'] .icon-sun { display: none; }
[data-theme='dark'] .icon-moon { display: block; }

main {
  max-width: 72rem;
  margin-inline: auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-4);
  text-align: center;
  font-family: var(--font-sans);
  font-size: var(--step--1);
  color: var(--text-muted);
}

.site-footer p { margin: 0 0 var(--space-2); }

/* ---------------------------------------------------------------------------
   Home
--------------------------------------------------------------------------- */
.hero {
  max-width: 46rem;
  padding-block: var(--space-5) var(--space-6);
}

.hero h1 {
  color: var(--text);
  margin-bottom: var(--space-3);
}

.hero-sub {
  font-size: var(--step-1);
  color: var(--text-muted);
  text-wrap: pretty;
}

.hero-links {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-sans);
  margin-top: var(--space-4);
}

.button {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
}

.button:hover { filter: brightness(1.1); }

.home-section { margin-block: var(--space-6); }
.home-section > p { font-family: var(--font-sans); font-size: var(--step--1); }

/* ---------------------------------------------------------------------------
   Article lists & work strip
--------------------------------------------------------------------------- */
.article-list,
.work-strip {
  list-style: none;
  margin: 0;
  padding: 0;
}

.article-list li {
  padding-block: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.article-list h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--step-1);
}

.article-list h3 a {
  color: var(--text);
  text-decoration: none;
}

.article-list h3 a:hover { color: var(--accent); }

.article-list .item-meta {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  color: var(--text-muted);
  margin: 0 0 var(--space-1);
}

.article-list .item-desc {
  margin: 0;
  color: var(--text-muted);
}

.work-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: var(--space-3);
}

.work-strip li {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: var(--shadow);
}

.work-strip h3 { font-size: var(--step-0); margin-bottom: var(--space-1); }
.work-strip h3 a { color: var(--text); text-decoration: none; }
.work-strip h3 a:hover { color: var(--accent); }
.work-strip p { margin: 0; font-size: var(--step--1); color: var(--text-muted); }

.listing { max-width: var(--measure); }
.listing-intro { color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   Article page
--------------------------------------------------------------------------- */
.article { max-width: var(--measure); margin-inline: auto; }

.article-header { margin-bottom: var(--space-4); }

.article-meta {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  color: var(--text-muted);
}

.tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0 var(--space-2);
  margin-left: var(--space-1);
  font-size: 0.85em;
}

.toc {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
}

.toc strong { display: block; margin-bottom: var(--space-2); }
.toc ol { margin: 0; padding-left: 1.2em; }
.toc a { color: var(--text-muted); text-decoration: none; }
.toc a:hover { color: var(--accent); }

.prose h2 { margin-top: var(--space-5); }
.prose h3 { margin-top: var(--space-4); }

.prose h2 a,
.prose h3 a {
  color: inherit;
  text-decoration: none;
}

.prose h2 a:hover::after,
.prose h3 a:hover::after {
  content: ' #';
  color: var(--accent);
}

.prose ul,
.prose ol { padding-left: 1.4em; margin: 0 0 var(--space-3); }
.prose li { margin-bottom: var(--space-1); }

.prose blockquote {
  margin: 0 0 var(--space-3);
  padding-left: var(--space-3);
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-5) auto;
  width: 40%;
}

.prose :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

/* Shiki code blocks: dual-theme via CSS variables */
.prose pre.shiki {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  line-height: 1.55;
  margin: 0 0 var(--space-4);
}

[data-theme='dark'] .shiki,
[data-theme='dark'] .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}

/* ---------------------------------------------------------------------------
   Interactive demos
--------------------------------------------------------------------------- */
[data-demo] {
  display: block;
  margin: var(--space-4) 0 var(--space-5);
  min-height: 12rem;
}

/* theme bridge into shadow DOM (custom properties pierce shadow boundaries) */
:root {
  --demo-bg: #fafbfc;
  --demo-surface: #ffffff;
  --demo-border: #e6e8eb;
  --demo-text: #1a1d21;
  --demo-muted: #6b7280;
  --demo-accent: #45607a;
  --demo-stack: #5b7c99;
  --demo-micro: #8479a8;
  --demo-task: #5c8a72;
  --demo-render: #a8737f;
}

[data-theme='dark'] {
  --demo-bg: #17191d;
  --demo-surface: #1f2227;
  --demo-border: #2a2d33;
  --demo-text: #e3e4e6;
  --demo-muted: #9099a3;
  --demo-accent: #9db4c8;
  --demo-stack: #8fabc4;
  --demo-micro: #a99ecb;
  --demo-task: #83b399;
  --demo-render: #c99aa5;
}

/* ---------------------------------------------------------------------------
   Small screens
--------------------------------------------------------------------------- */
@media (max-width: 40rem) {
  .site-nav { padding-inline: var(--space-3); }
  main { padding-inline: var(--space-3); }
  .hero { padding-block: var(--space-4) var(--space-5); }
}

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