:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --border: #222;
  --text: #e0e0e0;
  --text-secondary: #9ca3af;
  --accent: #4a9eff;
  --accent-dim: #2a6abf;
  --strong: #fff;
  --pre-bg: #1a1a1a;
  --pre-border: #2a2a2a;
  --max-width: 720px;
  --px: 2rem;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-secondary: #666;
  --accent: #2563eb;
  --accent-dim: #3b82f6;
  --strong: #000;
  --pre-bg: #f8f8f8;
  --pre-border: #e0e0e0;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { overflow-x: hidden; width: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

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

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  transition: border-color 0.2s;
  flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--text-secondary); }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1.5rem var(--px);
}
.site-header .inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.site-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.site-title:hover { text-decoration: none; color: var(--accent); }
.site-nav { display: flex; gap: 1rem; font-size: 0.85rem; align-items: center; }
.site-nav a { color: var(--text-secondary); }
.site-nav a:hover { color: var(--text); text-decoration: none; }

/* Main */
main {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 3rem var(--px);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Post list (index) */
.post-list { list-style: none; }
.post-item {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.post-item:last-child { border-bottom: none; }
.post-item-title {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.4rem;
}
.post-item-title a { color: var(--text); }
.post-item-title a:hover { color: var(--accent); text-decoration: none; }
.post-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}
.post-excerpt {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Article */
article {
  overflow-wrap: break-word;
  word-wrap: break-word;
  min-width: 0;
}
article h1 {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
}
article .post-meta { margin-bottom: 2rem; }
article h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
article h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 2rem 0 0.8rem;
}
article p { margin-bottom: 1rem; font-size: 0.95rem; }
article ul, article ol {
  margin: 0.5rem 0 1rem 1.5rem;
  font-size: 0.95rem;
}
article li { margin-bottom: 0.3rem; }
article strong { color: var(--strong); }
article blockquote {
  border-left: 3px solid var(--accent-dim);
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  color: var(--text-secondary);
  background: var(--surface);
  border-radius: 0 4px 4px 0;
}
article code {
  background: var(--surface);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  overflow-wrap: break-word;
}
article pre {
  background: var(--pre-bg);
  border: 1px solid var(--pre-border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  font-size: 0.82rem;
  line-height: 1.5;
}
article pre code {
  background: none;
  padding: 0;
  overflow-wrap: normal;
  word-break: normal;
}
article table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.88rem;
}
article th, article td {
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
article th {
  background: var(--surface);
  font-weight: 600;
  color: var(--strong);
}
article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem var(--px);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Mobile */
@media (max-width: 600px) {
  :root { --px: 1rem; }

  .site-header { padding: 0.8rem var(--px); }
  .site-title { font-size: 1rem; }
  .site-nav { gap: 0.7rem; font-size: 0.8rem; }

  main { padding: 1.5rem var(--px); }

  article h1 { font-size: 1.3rem; }
  article h2 { font-size: 1.1rem; }
  article h3 { font-size: 1rem; }
  article p, article ul, article ol { font-size: 0.9rem; }

  article pre { padding: 0.75rem; font-size: 0.7rem; border-radius: 4px; }
  article th, article td { padding: 0.3rem 0.5rem; font-size: 0.78rem; }
  article blockquote { padding: 0.4rem 0.8rem; margin: 0.8rem 0; font-size: 0.88rem; }

  .post-item { padding: 1rem 0; }
  .post-item-title { font-size: 1.05rem; }
  .post-excerpt { font-size: 0.85rem; }
}
