/* ---------- Tokens ---------- */
:root {
  --bg: #151515;
  --bg-elevated: #1c1c1c;
  --bg-pill: rgba(255, 255, 255, 0.08);
  --bg-pill-active: rgba(255, 255, 255, 0.12);
  --text: #f0efec;
  --text-muted: #c3c2b7;
  --text-faint: #8f8e86;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --link: #6da7ec;
  --link-underline: rgba(109, 167, 236, 0.4);
  --accent: #d97757;
  --code-bg: #111111;
  --code-text: #c3c2b7;
  --c-key: #6da7ec;
  --c-str: #e0b86a;
  --c-const: #8fd3c2;
  --c-fn: #d9a6e8;
  --c-id: #f0efec;

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --topbar-h: 56px;
  --sidebar-w: 264px;
  --outline-w: 256px;
  --content-max: 760px;
  --gutter: 16px;
}

:root[data-theme="light"] {
  --bg: #fcfbf8;
  --bg-elevated: #ffffff;
  --bg-pill: rgba(0, 0, 0, 0.05);
  --bg-pill-active: rgba(0, 0, 0, 0.08);
  --text: #1a1915;
  --text-muted: #4a4942;
  --text-faint: #7a7971;
  --border: rgba(0, 0, 0, 0.10);
  --border-strong: rgba(0, 0, 0, 0.18);
  --link: #2d6ccf;
  --link-underline: rgba(45, 108, 207, 0.4);
  --code-bg: #f3f2ee;
  --code-text: #3a3934;
  --c-key: #2d6ccf;
  --c-str: #a3651a;
  --c-const: #1f8a76;
  --c-fn: #8a3fa8;
  --c-id: #1a1915;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--link); text-decoration: underline; text-decoration-color: var(--link-underline); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--link); }

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  margin: 0;
  scroll-margin-top: calc(var(--topbar-h) + 24px);
}
h1 { font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.25rem); margin-bottom: 12px; }
h2 { font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem); margin-top: 48px; margin-bottom: 12px; }

p { color: var(--text-muted); font-size: 1.0625rem; line-height: 1.6; margin: 0 0 16px; }
ul { color: var(--text-muted); font-size: 1.0625rem; line-height: 1.6; padding-left: 22px; margin: 0 0 16px; }
li { margin-bottom: 6px; }
li strong { color: var(--text); font-weight: 600; }

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-pill);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 var(--gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-family: var(--font-serif); font-size: 1.125rem; font-weight: 600; }
.brand-icon { display: block; width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-strong); }
.topnav { display: flex; gap: 4px; margin-left: auto; margin-right: auto; }
.pill {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9375rem;
  padding: 6px 14px;
  border-radius: 999px;
}
.pill:hover, .pill.active { background: var(--bg-pill); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.menu-btn, .theme-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu-btn:hover, .theme-btn:hover { background: var(--bg-pill); }
.menu-btn { display: none; }
.icon-moon { display: none; }
:root[data-theme="light"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun { display: none; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--outline-w);
  min-height: calc(100vh - var(--topbar-h));
}

/* Left panel */
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 24px 12px;
  border-right: 1px solid var(--border);
  font-size: 0.875rem;
}
.sidebar-group { margin-bottom: 24px; }
.sidebar-heading { font-weight: 600; color: var(--text); padding: 6px 12px; margin-bottom: 2px; }
.sidebar-link {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
}
.sidebar-link.sub { padding-left: 24px; }
.sidebar-link:hover { background: var(--bg-pill); color: var(--text); }
.sidebar-link.active { background: var(--bg-pill-active); color: var(--text); }

/* Center panel */
.content {
  padding: 32px 48px 64px;
  min-width: 0;
}
.section { max-width: var(--content-max); margin: 0 auto; padding-bottom: 40px; scroll-margin-top: var(--topbar-h); }
.section + .section { border-top: 1px solid var(--border); padding-top: 32px; }
.crumbs { font-size: 0.875rem; color: var(--text-faint); margin-bottom: 20px; display: flex; gap: 8px; }
.lede { font-size: 1.125rem; color: var(--text); }

/* Right panel */
.outline {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 32px 24px 32px 16px;
  font-size: 0.875rem;
}
.outline-title { font-weight: 600; margin-bottom: 8px; padding-left: 12px; }
.outline a {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  padding: 5px 12px;
  border-left: 2px solid var(--border);
}
.outline a.sub { padding-left: 24px; }
.outline a:hover { color: var(--text); }
.outline a.active { color: var(--text); border-left-color: var(--text); }

/* ---------- Components ---------- */
.codeblock {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 24px 0 8px;
  overflow: hidden;
}
.codeblock-tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--border); }
.codeblock-tabs .tab { font-size: 0.8125rem; color: var(--text-faint); padding: 6px 10px; border-radius: 6px 6px 0 0; }
.codeblock-tabs .tab.active { color: var(--text); background: var(--bg-pill); }
.codeblock pre { margin: 0; padding: 16px; overflow-x: auto; font-family: var(--font-mono); font-size: 0.8125rem; line-height: 1.65; color: var(--code-text); }
.codeblock pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
.c-key { color: var(--c-key); } .c-str { color: var(--c-str); } .c-const { color: var(--c-const); } .c-fn { color: var(--c-fn); } .c-id { color: var(--c-id); }

.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 20px 0 8px;
  background: var(--bg-elevated);
}
.callout-title { font-weight: 600; font-size: 0.9375rem; margin-bottom: 4px; }
.callout p { margin: 0; font-size: 1rem; }
.callout.tldr { margin: 8px 0 28px; }
.callout.tldr .callout-title { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.callout-icon { color: var(--accent); flex: 0 0 16px; }
.callout.tldr .callout-body p { margin: 0 0 6px; font-size: 0.9375rem; }
.callout.tldr .callout-body ul { margin: 0; padding-left: 20px; }
.callout.tldr .callout-body li { margin: 4px 0; font-size: 0.9375rem; line-height: 1.55; }
.callout.tldr .callout-body code { font-size: 0.85em; }
.callout.tldr .callout-note { margin: 10px 0 0; font-size: 0.8125rem; color: var(--text-faint); }


/* Testimonial carousel */
.carousel { margin: 28px 0 8px; }
.carousel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.carousel-title { font-size: 1.0625rem; margin: 0; }
.carousel-controls { display: flex; gap: 6px; }
.carousel-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.carousel-btn:hover { background: var(--bg-pill); }
.carousel-btn:disabled { opacity: 0.35; cursor: default; }

.carousel-track {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-behavior: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 2px;
  margin: -2px;
  outline: none;
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track:focus-visible { box-shadow: 0 0 0 2px var(--link-underline); border-radius: 12px; }

.testimonial {
  flex: 0 0 min(100%, 440px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
}
.testimonial-stars { display: flex; gap: 2px; }
.star { display: inline-flex; color: var(--border-strong); }
.star.full { color: var(--accent); }
.star.half { color: var(--accent); position: relative; }
.star.half svg { clip-path: inset(0 50% 0 0); }
.star.half::after { content: ""; position: absolute; inset: 0; }
.star svg { fill: currentColor; }

.testimonial-quote {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
  flex: 1;
}
.testimonial-quote::before { content: "\201C"; color: var(--accent); margin-right: 2px; }
.testimonial-quote::after { content: "\201D"; color: var(--accent); margin-left: 2px; }
.testimonial-person { display: flex; align-items: center; gap: 12px; }
.testimonial-photo {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 44px;
  border: 1px solid var(--border);
  background: var(--bg-pill);
}
.testimonial-initials {
  width: 44px; height: 44px;
  border-radius: 50%;
  flex: 0 0 44px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.875rem; font-weight: 600;
  color: var(--text);
  background: var(--bg-pill-active);
  border: 1px solid var(--border);
}
.testimonial-name { font-size: 0.9375rem; font-weight: 600; color: var(--text); margin: 0; }
.testimonial-role { font-size: 0.8125rem; color: var(--text-faint); margin: 0; }


/* Contact form */
.contact-form { display: flex; flex-direction: column; gap: 18px; margin: 16px 0 8px; }
.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field label { font-size: 0.875rem; font-weight: 500; color: var(--text); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.counter { font-size: 0.8125rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.counter.near { color: var(--accent); }
.field input, .field textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }
.field input:focus, .field textarea:focus { border-color: var(--link); box-shadow: 0 0 0 3px var(--link-underline); }
.field.invalid input, .field.invalid textarea { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
.error { font-size: 0.8125rem; color: var(--accent); min-height: 1em; }

.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.suggestion {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--bg-pill);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggestion:hover, .suggestion:focus-visible { background: var(--bg-pill-active); color: var(--text); border-color: var(--border-strong); outline: none; }
.suggestion strong { color: var(--text); font-weight: 500; }

.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.btn-primary {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--bg);
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.form-status { font-size: 0.875rem; color: var(--text-muted); }
.form-status.ok { color: var(--c-const); }
.form-status.err { color: var(--accent); }

.footer { max-width: var(--content-max); margin: 48px auto 0; padding-top: 24px; border-top: 1px solid var(--border); font-size: 0.875rem; color: var(--text-faint); }

.scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, 0.5); }


/* ---------- Blog ---------- */
.post-list { display: flex; flex-direction: column; margin-top: 8px; }
.post-card { padding: 22px 0; border-top: 1px solid var(--border); }
.post-card:last-child { border-bottom: 1px solid var(--border); }
.post-meta { display: flex; gap: 8px; align-items: center; font-size: 0.8125rem; color: var(--text-faint); margin-bottom: 6px; }
.post-meta .dot { opacity: 0.6; }
.post-card-title { font-size: 1.25rem; margin: 0 0 6px; }
.post-card-title a { color: var(--text); text-decoration: none; }
.post-card-title a:hover { text-decoration: underline; text-decoration-color: var(--link-underline); }
.post-card-summary { margin: 0 0 10px; font-size: 1rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 0.75rem; color: var(--text-muted); text-decoration: none; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-pill); }
.tag:hover { color: var(--text); border-color: var(--border-strong); }
.post-tags { margin-top: 28px; }
.post-back { margin-top: 24px; font-size: 0.9375rem; }
.empty { color: var(--text-faint); }
.outline .count { color: var(--text-faint); font-size: 0.75rem; margin-left: 4px; }
.outline a.sub2 { padding-left: 36px; font-size: 0.8125rem; }

.post h1 { margin-bottom: 8px; }
.post .post-meta { margin-bottom: 16px; }
.post-body { margin-top: 8px; }
.post-body h2 { margin-top: 40px; }
.post-body h3 { font-size: 1.125rem; margin-top: 28px; margin-bottom: 8px; }
.post-body p, .post-body ul, .post-body ol { color: var(--text-muted); font-size: 1.0625rem; line-height: 1.65; }
.post-body ol { padding-left: 22px; margin: 0 0 16px; }
.post-body img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); margin: 8px 0; }
.post-body blockquote { margin: 20px 0; padding: 4px 18px; border-left: 3px solid var(--accent); color: var(--text-muted); }
.post-body blockquote p { margin: 8px 0; }
.post-body pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 16px 0; font-family: var(--font-mono); font-size: 0.8125rem; line-height: 1.6; color: var(--code-text); }
.post-body pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
.code-wrap { position: relative; }
.code-wrap pre { padding-right: 72px; }
.copy-btn { position: absolute; top: 8px; right: 8px; font: inherit; font-size: 0.75rem; font-weight: 500; line-height: 1; padding: 6px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-muted); cursor: pointer; opacity: 0; transition: opacity .15s ease, color .15s ease; }
.code-wrap:hover .copy-btn, .copy-btn:focus-visible, .copy-btn.done { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn.done { color: var(--c-const); border-color: var(--c-const); }
@media (hover: none) { .copy-btn { opacity: 1; } }
.post-body hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }
.post-body table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; margin: 16px 0; }
.post-body th, .post-body td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.post-body th { color: var(--text); font-weight: 600; }
.post-body a { color: var(--link); }

/* Recent writing on the home page */
.recent-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 12px; }
.recent-item { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elevated); text-decoration: none; }
.recent-item:hover { border-color: var(--border-strong); }
.recent-title { color: var(--text); font-weight: 500; font-size: 0.9375rem; }
.recent-meta { color: var(--text-faint); font-size: 0.8125rem; }
.recent-item .recent-summary { color: var(--text-muted); font-size: 0.875rem; margin: 2px 0 0; }
.recent-all { font-size: 0.9375rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .outline { display: none; }
}

@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-flex; }
  .topnav { display: none; }
  .brand-name { font-size: 1.0625rem; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(300px, 85vw);
    height: auto;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 0 1px var(--border);
  }
  .sidebar.open { transform: translateX(0); }

  .content { padding: 24px var(--gutter) 48px; }
  h2 { margin-top: 36px; }
  .testimonial { flex-basis: 88%; }
  .codeblock pre { font-size: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .sidebar { transition: none; }
}
