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

/* ── Tokens ──────────────────────────────────── */

:root {
  --text:    #111;
  --muted:   #888;
  --border:  #e8e8e8;
  --bg:      #fff;
  --code-bg: #f5f5f5;
  --width:   960px;
  --sidebar: 220px;
  --gap:     56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text:    #e2e2e2;
    --border:  #2c2c2c;
    --bg:      #111;
    --code-bg: #1c1c1c;
  }
}

[data-theme="dark"] {
  --text:    #e2e2e2;
  --border:  #2c2c2c;
  --bg:      #111;
  --code-bg: #1c1c1c;
}

/* ── Base ────────────────────────────────────── */

html { font-size: 17px; }

body {
  font-family: system-ui, sans-serif;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  transition: color 0.15s, background-color 0.15s;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}

h1 { font-size: 1.5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; }

p { margin: 0 0 1.2rem; }

a {
  color: inherit;
  text-decoration: none;
}

blockquote {
  margin: 1.5rem 0;
  padding-left: 1.25rem;
  border-left: 2px solid var(--border);
  color: var(--muted);
}

code {
  font-family: ui-monospace, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1.25rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

pre code { background: none; padding: 0; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ── Header ──────────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--border);
  padding: 24px 0;
}

.header-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.site-title:hover { opacity: 0.6; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  font-size: 0.875rem;
  color: var(--muted);
}

.nav-link:hover,
.nav-link.active { color: var(--text); }

/* ── Layout ──────────────────────────────────── */

.page-wrapper {
  max-width: var(--width);
  margin: 52px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 1fr var(--sidebar);
  gap: var(--gap);
  align-items: start;
}

.main-content { min-width: 0; }

/* ── Sidebar ─────────────────────────────────── */

.sidebar {
  font-size: 0.8rem;
  position: sticky;
  top: 32px;
}

.sidebar-section + .sidebar-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 10px;
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-list li {
  margin-bottom: 6px;
  line-height: 1.4;
}

.sidebar-list a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--border);
}

.sidebar-list a:hover { text-decoration-color: var(--text); }

.sidebar-note {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Content (prose) ─────────────────────────── */

.content { max-width: 640px; }

.content a {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
}

.content a:hover { text-decoration-color: var(--text); }

.content h2,
.content h3 { margin-top: 2rem; }

/* ── Posts ───────────────────────────────────── */

.post-header { margin-bottom: 2rem; }

.post-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-item {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.post-item:first-child { border-top: 1px solid var(--border); }

.post-date {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 80px;
  flex-shrink: 0;
}

.post-link:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Home ────────────────────────────────────── */

.home-intro {
  max-width: 560px;
  margin-bottom: 3rem;
  line-height: 1.75;
}

/* ── Theme toggle ────────────────────────────── */

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--muted);
  display: flex;
  align-items: center;
}

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

.icon-sun  { display: none; }
.icon-moon { display: block; }

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

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* ── Footer ──────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 72px;
}

.footer-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 0 24px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Responsive ──────────────────────────────── */

@media (max-width: 760px) {
  .page-wrapper {
    grid-template-columns: 1fr;
    margin: 36px auto;
  }

  .sidebar {
    position: static;
    border-top: 1px solid var(--border);
    padding-top: 32px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}
