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

/* Colors */
:root {
  --bg: #0d0d0d;
  --fg: #e0e0e0;
  --muted: #888;
  --link: #7aa2ff;
  --link-hover: #a8c4ff;
  --codebg: #161616;
  --codeborder: #2a2a2a;
  --border: #222;
  --accent: #7aa2ff;
}

/* Light mode override */
:root[data-theme="light"] {
  --bg: #fdfdfd;
  --fg: #111;
  --muted: #666;
  --link: #0b57d0;
  --link-hover: #083fa0;
  --codebg: #f3f3f3;
  --codeborder: #ddd;
  --border: #ddd;
  --accent: #0b57d0;
}

/* Base */
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.7;
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  -webkit-font-smoothing: antialiased;
}

/* Links */
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

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

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}
.theme-toggle:hover { color: var(--fg); }

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

/* Post list (home) */
.post-list { list-style: none; }
.post-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.4rem 0;
}
.post-list .post-date {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-left: 1rem;
}

/* Article */
.post-header { margin-bottom: 2rem; }
.post-title {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}
.post-meta {
  color: var(--muted);
  font-size: 0.85rem;
}
.post-tags { margin-top: 0.3rem; }
.post-tags a {
  color: var(--muted);
  font-size: 0.8rem;
  margin-right: 0.5rem;
}
.post-tags a::before { content: "#"; }

/* Article layout with sidebar ToC */
.article-layout {
  display: flex;
  gap: 3rem;
}
.article-layout .content {
  flex: 1;
  min-width: 0;
}
.toc-sidebar {
  width: 200px;
  flex-shrink: 0;
}
.toc {
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  scrollbar-width: none;
}
.toc::-webkit-scrollbar { display: none; }
.toc h2 {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.toc ul {
  list-style: none;
  padding-left: 0;
}
.toc ul ul {
  padding-left: 0.8rem;
}
.toc li {
  margin-bottom: 0.2rem;
}
.toc a {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}
.toc a:hover {
  color: var(--fg);
}

/* Content */
.content h2 {
  font-size: 1.3rem;
  margin-top: 2.5rem;
  margin-bottom: 0.8rem;
  font-weight: 600;
}
.content h3 {
  font-size: 1.1rem;
  margin-top: 2rem;
  margin-bottom: 0.6rem;
  font-weight: 600;
}
.content p { margin-bottom: 1rem; }
.content ul, .content ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}
.content li { margin-bottom: 0.3rem; }
.content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 1rem 0;
}
.content strong { font-weight: 600; }
ol.footnotes {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #555;
  padding-left: 1.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}
ol.footnotes a { color: var(--link); }
.closing {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #555;
}
figure { margin: 1rem 0; }
figure img { max-width: 100%; height: auto; border-radius: 4px; }
figure img.invertible { filter: none; }
:root:not([data-theme="light"]) figure img.invertible { filter: invert(1) hue-rotate(180deg); }
figcaption {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.4rem;
  line-height: 1.4;
}

/* Code */
code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--codebg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}
pre {
  background: var(--codebg);
  border: 1px solid var(--codeborder);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1rem;
  line-height: 1.5;
}
pre code {
  background: none;
  padding: 0;
  font-size: 0.82em;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
th, td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Archive page */
.archive-year {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
  color: var(--muted);
}

/* Tags page */
.tag-list { list-style: none; }
.tag-list li { display: inline-block; margin: 0.3rem 0.5rem 0.3rem 0; }
.tag-list a {
  color: var(--muted);
  font-size: 0.9rem;
}
.tag-list a::before { content: "#"; }

/* About page */
.about-content h2 { margin-top: 2rem; }

/* HN mode: ?hn=1 strips chrome */
body.hn-mode .site-header,
body.hn-mode .site-footer { display: none; }
body.hn-mode { max-width: 720px; padding-top: 1rem; }

/* Widen body when sidebar ToC is present */
body:has(.article-layout) {
  max-width: 920px;
}

/* Mobile ToC toggle */
.toc-toggle, .toc-overlay { display: none; }

/* Responsive */
@media (max-width: 900px) {
  body:has(.article-layout) { max-width: 680px; }
  .article-layout {
    flex-direction: column;
    gap: 0;
  }
  .toc-toggle {
    display: block;
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1001;
    background: var(--codebg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 1.3rem;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
  }
  .toc-toggle:hover { color: var(--fg); }
  .toc-sidebar {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 260px;
    height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    padding: 3.5rem 1.5rem 2rem;
    z-index: 1000;
    overflow-y: auto;
  }
  .toc-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
  }
  .toc-open .toc-sidebar { display: block; }
  .toc-open .toc-overlay { display: block; }
  .toc-open .toc-toggle { color: var(--fg); }
  .toc {
    position: static;
    max-height: none;
  }
}
@media (max-width: 600px) {
  body { padding: 1.5rem 1rem; }
  .site-header { flex-direction: column; gap: 0.5rem; }
  .post-title { font-size: 1.3rem; }
  .post-list li { flex-direction: column; gap: 0.1rem; }
}
