/* ---- Theme tokens: light by default, dark via OS preference or [data-theme] ---- */
:root {
  --bg: #faf8f3;          /* warm off-white */
  --text: #21201b;
  --muted: #6d6860;
  --rule: #e3e0d6;
  --link: #1a4fa0;
  --selection: #ece6d8;
  --toggle-bg: rgba(0,0,0,0.05);
  --toggle-border: rgba(0,0,0,0.12);
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#19191b; --text:#e7e3da; --muted:#9b968b; --rule:#34332d; --link:#9dc0ff; --selection:#33322b; --toggle-bg:rgba(255,255,255,0.07); --toggle-border:rgba(255,255,255,0.16); }
}
:root[data-theme="light"] { --bg:#faf8f3; --text:#21201b; --muted:#6d6860; --rule:#e3e0d6; --link:#1a4fa0; --selection:#ece6d8; --toggle-bg:rgba(0,0,0,0.05); --toggle-border:rgba(0,0,0,0.12); }
:root[data-theme="dark"]  { --bg:#19191b; --text:#e7e3da; --muted:#9b968b; --rule:#34332d; --link:#9dc0ff; --selection:#33322b; --toggle-bg:rgba(255,255,255,0.07); --toggle-border:rgba(255,255,255,0.16); }

html { font-size: 19px; }

body {
  margin: 0 auto;
  padding: 4.75rem 1.25rem 5rem;
  max-width: 38rem;
  background: var(--bg);
  color: var(--text);
  font-family: Charter, Georgia, 'Times New Roman', serif;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--selection); }

h1 { font-size: 2rem; font-weight: 600; line-height: 1.2; margin: 0 0 0.85rem; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; font-weight: 600; margin: 2.5rem 0 0.85rem; letter-spacing: -0.005em; }

p { margin: 0 0 1.25rem; }

a {
  color: inherit;                 /* links take the text colour: black in light, white in dark */
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
}
a:hover { text-decoration-color: currentColor; }

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

.navbar-right { display: flex; align-items: center; gap: 0.9rem; }
.lang { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.lang a { color: var(--muted); }

.bio { margin: 0 0 1rem; color: var(--muted); }

ul.entries { list-style: none; padding: 0; margin: 0; }
ul.entries li { margin: 0.55rem 0; }
ul.entries .date { color: var(--muted); }

section.about p { margin: 0 0 0.6rem; }

.back { display: inline-block; margin: 0 0 2rem; font-size: 0.9rem; }
.article-date { color: var(--muted); font-size: 0.9rem; margin: 0 0 2.25rem; }
article h1 { margin-bottom: 0.3rem; }
article blockquote { margin: 1.5rem 0; padding-left: 1.1rem; border-left: 3px solid var(--rule); color: var(--muted); font-style: italic; }
article img { max-width: 100%; height: auto; display: block; margin: 2rem auto; }
/* Diagrams (SVG) are rendered light; invert them in dark mode so they fit the page. Raster images are left untouched. */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) article img[src$=".svg"] { filter: invert(1) hue-rotate(180deg); } }
:root[data-theme="dark"] article img[src$=".svg"] { filter: invert(1) hue-rotate(180deg); }

footer {
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---- Top navbar: brand + theme switch; retracts on scroll-down, returns on scroll-up ---- */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  transition: transform 0.28s ease;
}
.navbar.nav-hidden { transform: translateY(-100%); }
.navbar-inner {
  max-width: 38rem; margin: 0 auto; padding: 0.6rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-size: 0.95rem; font-weight: 600; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }

/* slider switch */
.theme-toggle {
  position: relative; flex: none; width: 2.7rem; height: 1.5rem; padding: 0;
  border: 1px solid var(--toggle-border); border-radius: 999px;
  background: var(--toggle-bg); cursor: pointer;
}
.theme-toggle .knob {
  position: absolute; top: 1px; left: 1px;
  width: calc(1.5rem - 4px); height: calc(1.5rem - 4px); border-radius: 50%;
  background: var(--muted); transition: transform 0.18s ease, background 0.18s ease;
}
.theme-toggle[aria-checked="true"] .knob { transform: translateX(calc(2.7rem - 1.5rem)); background: var(--text); }
