/* ---- Design tokens ---------------------------------------------------- */
:root,
[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --sidebar-bg: #ffffff;
  --border: #e3e5e8;
  --text: #3d4148;
  --muted: #6b717b;
  --heading: #1c1e22;
  --link: #1a6fb5;
  --code-bg: #f0f2f5;
  --tok-comment: #6a737d;
  --tok-keyword: #b3261e;
  --tok-string: #0b6e4f;
  --tok-number: #8a4b00;
  --tok-func: #5b3fc4;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #1b1b1e;
  --surface: #222326;
  --sidebar-bg: #17181a;
  --border: #323438;
  --text: #b4b6ba;
  --muted: #868a91;
  --heading: #e4e5e7;
  --link: #5eaee8;
  --code-bg: #26282c;
  --tok-comment: #7d8590;
  --tok-keyword: #ff8b82;
  --tok-string: #7ee0b0;
  --tok-number: #f0b36a;
  --tok-func: #b9a6ff;
  color-scheme: dark;
}

/* ---- Base --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { color: var(--heading); line-height: 1.25; }
small { color: var(--muted); font-weight: 400; }
.icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.2em; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 8px; top: 8px; z-index: 10; background: var(--surface); padding: 6px 10px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar {
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.avatar img { width: 44px; height: 44px; border-radius: 50%; display: block; }
.site-title { color: var(--heading); font-weight: 700; font-size: 1.1rem; }
.site-tagline { margin: 0; color: var(--muted); font-size: .85rem; display: none; }
.sidebar-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.sidebar-nav a { color: var(--text); display: inline-flex; align-items: center; gap: 8px; padding: 4px 0; }
.sidebar-nav a:hover { color: var(--heading); text-decoration: none; }
.sidebar-nav a[aria-current="page"] { color: var(--heading); font-weight: 600; }
.sidebar-bottom { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.sidebar-bottom a, .theme-toggle { color: var(--muted); display: inline-flex; }
.sidebar-bottom a:hover, .theme-toggle:hover { color: var(--heading); }
.theme-toggle { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }
.separator { width: 1px; height: 1.2em; background: var(--border); }
[data-theme="dark"] .when-light, [data-theme="light"] .when-dark { display: none; }

/* ---- Content ------------------------------------------------------------ */
.wrapper { min-height: 100vh; display: flex; flex-direction: column; }
.main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 24px 16px; }
.footer { padding: 24px 16px; text-align: center; color: var(--muted); font-size: .85rem; }
.footer p { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.post-list { list-style: none; margin: 0; padding: 0; }
.card-title { margin: 0 0 6px; font-size: 1.3rem; }
.card-title a { color: var(--heading); }
.card-excerpt { margin: 0 0 10px; }
.meta { margin: 0; color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
.meta .icon { margin-right: 5px; }
.tag { display: inline-block; background: var(--code-bg); border-radius: 4px; padding: 0 7px; margin-right: 6px; color: var(--text); }
.tag:hover { color: var(--heading); text-decoration: none; }
.pagination { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }

.page-title, .post-title { margin: 0 0 12px; font-size: 1.9rem; }
.post-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; }
.post, .page { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px; min-width: 0; }
.post-header { margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.post-footer { margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.share { gap: 14px; }
.comments { margin-top: 32px; }

.toc-panel { display: none; font-size: .85rem; }
.toc-title { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; }
.toc ul { list-style: none; margin: 0; padding-left: 14px; border-left: 1px solid var(--border); }
.toc > ul { padding-left: 0; border: 0; }
.toc li { margin: 4px 0; }
.toc a { color: var(--muted); }
.toc a:hover { color: var(--heading); }

.archive-year h2 { font-size: 1.2rem; margin: 24px 0 8px; }
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.archive-list time { color: var(--muted); font-size: .85rem; margin-right: 12px; font-variant-numeric: tabular-nums; }

/* ---- Prose -------------------------------------------------------------- */
.prose { overflow-wrap: anywhere; }
.prose h1 { font-size: 1.6rem; margin: 1.6em 0 .6em; }
.prose h2 { font-size: 1.35rem; margin: 1.6em 0 .6em; }
.prose h3 { font-size: 1.15rem; margin: 1.4em 0 .5em; }
.prose > :first-child { margin-top: 0; }
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.prose img { border-radius: 6px; margin: 8px 0; }
.prose blockquote { margin: 1em 0; padding: 0 1em; border-left: 3px solid var(--border); color: var(--muted); }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 12px; }
.prose code { background: var(--code-bg); border-radius: 4px; padding: .1em .35em; font: .88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; overflow-x: auto; overflow-wrap: normal; }
.prose pre code { background: none; padding: 0; font-size: .85em; }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--tok-comment); font-style: italic; }
.token.keyword, .token.selector, .token.important, .token.atrule, .token.boolean { color: var(--tok-keyword); }
.token.string, .token.char, .token.attr-value, .token.inserted { color: var(--tok-string); }
.token.number, .token.constant, .token.symbol, .token.deleted { color: var(--tok-number); }
.token.function, .token.class-name, .token.builtin, .token.property { color: var(--tok-func); }

/* ---- Wide screens: fixed sidebar and sticky table of contents ----------- */
@media (min-width: 992px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px;
    flex-direction: column; align-items: stretch; flex-wrap: nowrap;
    padding: 32px 24px 20px; border-bottom: 0; border-right: 1px solid var(--border);
    overflow-y: auto; gap: 24px;
  }
  .sidebar-brand { flex-direction: column; text-align: center; gap: 8px; }
  .avatar img { width: 96px; height: 96px; }
  .site-title { font-size: 1.25rem; }
  .site-tagline { display: block; }
  .sidebar-nav ul { flex-direction: column; gap: 2px; }
  .sidebar-nav a { padding: 8px 10px; border-radius: 8px; width: 100%; }
  .sidebar-nav a[aria-current="page"] { background: var(--code-bg); }
  .sidebar-bottom { margin: auto 0 0; justify-content: center; }
  .wrapper { margin-left: 260px; }
  .main { padding: 40px 32px; }
}
@media (min-width: 1280px) {
  .post-grid { grid-template-columns: minmax(0, 1fr) 220px; }
  .toc-panel { display: block; position: sticky; top: 24px; align-self: start; }
}
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@media print { .sidebar, .comments, .toc-panel, .share { display: none; } .wrapper { margin: 0; } }
