/* ---------- Theme tokens ---------- */
:root {
  color-scheme: light;
  --bg: #fbfaf8;
  --bg-soft: #f3f1ec;
  --fg: #1b1a18;
  --muted: #6b665f;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --border: #e6e2db;
  --surface: #f3f1ec;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.04), 0 8px 24px rgba(20, 20, 19, 0.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  --max: 44rem;
}

/* JS-disabled fallback: follow the OS preference. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141413;
    --bg-soft: #1d1c1a;
    --fg: #e9e6e1;
    --muted: #a09b93;
    --accent: #7aa2f7;
    --accent-soft: rgba(122, 162, 247, 0.16);
    --border: #34322e;
    --surface: #1f1e1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

/* Explicit choice (set by the theme toggle) always wins over the media query. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fbfaf8;
  --bg-soft: #f3f1ec;
  --fg: #1b1a18;
  --muted: #6b665f;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --border: #e6e2db;
  --surface: #f3f1ec;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.04), 0 8px 24px rgba(20, 20, 19, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413;
  --bg-soft: #1d1c1a;
  --fg: #e9e6e1;
  --muted: #a09b93;
  --accent: #7aa2f7;
  --accent-soft: rgba(122, 162, 247, 0.16);
  --border: #34322e;
  --surface: #1f1e1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.container {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.5rem;
}

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

a:hover { text-decoration: underline; }

h1, h2, h3, h4 {
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.015em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

img { max-width: 100%; height: auto; }

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

/* ---------- Header ---------- */
.site-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  backdrop-filter: saturate(1.4) blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
  margin-bottom: 3rem;
}

.site-header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  max-width: var(--max);
  margin: 0 auto;
}

.nav-end {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-header ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 1.5rem;
}

.site-header a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.15s ease;
}

.site-header a:hover { color: var(--fg); text-decoration: none; }

.brand {
  font-weight: 650;
  font-size: 1.05rem;
  color: var(--fg) !important;
  letter-spacing: -0.01em;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease,
    background-color 0.15s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.theme-toggle:active { transform: scale(0.92); }

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Home ---------- */
.home h1 {
  font-size: 2.4rem;
  margin: 0 0 0.4rem;
}

.tagline {
  color: var(--muted);
  font-size: 1.2rem;
  margin-top: 0;
}

/* ---------- Post list ---------- */
.post-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0;
}

.post-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

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

.post-list a {
  color: var(--fg);
  font-weight: 500;
}

.post-list a:hover { color: var(--accent); text-decoration: none; }

.post-list .meta {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.post header h1 { font-size: 2.3rem; margin: 0 0 0.5rem; }

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

.content > :first-child { margin-top: 0; }

.content :is(h2, h3, h4) {
  margin-top: 2.25em;
  margin-bottom: 0.6em;
}

.content p,
.content ul,
.content ol { margin: 0 0 1.15em; }

.content a { text-decoration: underline; text-underline-offset: 2px; }

.content blockquote {
  margin: 1.5em 0;
  padding: 0.4em 1.2em;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
}

.content blockquote p:last-child { margin-bottom: 0; }

.content pre {
  background: var(--surface);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.6;
  border: 1px solid var(--border);
}

.content :not(pre) > code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

.content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 1em;
}

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5em 0;
  font-size: 0.95rem;
}

.content th,
.content td {
  border: 1px solid var(--border);
  padding: 0.5em 0.75em;
  text-align: left;
}

.content th { background: var(--surface); font-weight: 600; }

/* ---------- Table of contents ---------- */
.toc {
  margin: 1.75rem 0 2.5rem;
  padding: 1.1rem 1.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
}

.toc-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.toc nav { margin: 0; }

.toc ul { margin: 0; padding-left: 1.2rem; }

.toc ul ul { padding-left: 1rem; }

.toc li { margin: 0.3rem 0; }

.toc a {
  color: var(--muted);
  text-decoration: none;
}

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

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

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
