/* siftwise blog: one stylesheet, light and dark via prefers-color-scheme. */

:root {
  --bg: #fbfbfa;
  --fg: #1f2328;
  --muted: #59636e;
  --accent: #0e7c66;
  --accent-soft: #e3f3ee;
  --border: #d8dee4;
  --surface: #f3f5f4;
  --code-bg: #f4f6f5;
  --code-fg: #24292f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);

  /* Prism tokens */
  --tok-comment: #6e7781;
  --tok-keyword: #a8327a;
  --tok-string: #0a6f3c;
  --tok-number: #0550ae;
  --tok-function: #6639ba;
  --tok-property: #953800;
  --tok-variable: #0550ae;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 40rem; /* about 70 characters at the 18px body size */

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1214;
    --fg: #e6edf3;
    --muted: #9aa4ae;
    --accent: #3fc1a5;
    --accent-soft: #12302a;
    --border: #2d343b;
    --surface: #161b20;
    --code-bg: #161b20;
    --code-fg: #e6edf3;
    --shadow: none;

    --tok-comment: #8b949e;
    --tok-keyword: #ff7b72;
    --tok-string: #7ee2b8;
    --tok-number: #79c0ff;
    --tok-function: #d2a8ff;
    --tok-property: #ffa657;
    --tok-variable: #79c0ff;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 1.5rem;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
}

/* ---------- Layout ---------- */

.wrap {
  max-width: calc(var(--measure) + 2rem);
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  border-bottom: 1px solid var(--border);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
}
.brand img { width: 22px; height: 26px; }
.site-nav { display: flex; gap: 1.1rem; font-size: 0.95rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--accent); }

main.wrap { padding-top: 2.5rem; padding-bottom: 3rem; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1.5rem 0 2.5rem;
}
.site-footer p { margin: 0.25rem 0; }

/* ---------- Typography ---------- */

h1, h2, h3 {
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1 { font-size: clamp(2rem, 5vw, 2.6rem); margin: 0 0 0.75rem; letter-spacing: -0.02em; }
h2 {
  font-size: 1.6rem;
  margin: 3rem 0 0.75rem;
  padding-top: 0.5rem;
}
h3 { font-size: 1.2rem; margin: 2rem 0 0.5rem; }
h2 a.anchor, h3 a.anchor {
  color: var(--border);
  text-decoration: none;
  margin-left: 0.35rem;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s;
}
h2:hover a.anchor, h3:hover a.anchor, a.anchor:focus { opacity: 1; color: var(--muted); }

p, ul, ol, table, figure, pre, blockquote { margin: 0 0 1.25rem; }
ul, ol { padding-left: 1.4rem; }
li { margin: 0.3rem 0; }
li > ul, li > ol { margin: 0.3rem 0 0; }

a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

strong { font-weight: 650; }

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

code, kbd {
  font-family: var(--font-mono);
  font-size: 0.86em;
}
:not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.08em 0.32em;
  overflow-wrap: anywhere;
}

blockquote {
  border-left: 3px solid var(--accent);
  margin-left: 0;
  padding: 0.1rem 0 0.1rem 1rem;
  color: var(--muted);
}

/* ---------- Article ---------- */

.post-header { margin-bottom: 2rem; }
.kicker {
  color: var(--accent);
  font-weight: 650;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
}
.byline {
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  margin: 0;
}
.byline span + span::before { content: "·"; margin-right: 0.6rem; }

.lead { font-size: 1.25rem; line-height: 1.6; color: var(--fg); }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem 0.75rem;
  margin: 0 0 2.5rem;
  font-size: 0.98rem;
}
.toc h2 {
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5rem;
  padding: 0;
}
.toc ol { margin: 0 0 0.25rem; padding-left: 1.3rem; }
.toc li { margin: 0.15rem 0; }
.toc a { color: var(--fg); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }

.callout {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.85rem 1.1rem;
  margin: 0 0 1.5rem;
  font-size: 1rem;
}
.callout p:last-child { margin-bottom: 0; }

/* ---------- Figures ---------- */

figure { margin-left: 0; margin-right: 0; }
figure img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}
figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-top: 0.6rem;
}

.diagram {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  overflow-x: auto;
}
pre.mermaid {
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  text-align: center;
  font-family: var(--font-body);
  /* Shown as text until Mermaid renders it (or if the CDN is blocked). */
  white-space: pre;
  color: var(--muted);
  font-size: 0.85rem;
}
pre.mermaid[data-processed] { white-space: normal; }
pre.mermaid svg { max-width: 100%; height: auto; }

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  margin: 0 0 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0;
}
th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th { background: var(--surface); font-weight: 650; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Code blocks ---------- */

.code {
  position: relative;
  margin: 1.75rem 0 1.5rem;
}
.code-label {
  position: absolute;
  top: 0;
  left: 0.9rem;
  transform: translateY(-50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
}
pre[class*="language-"] {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1rem 1rem;
  margin: 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.6;
  tab-size: 4;
}
pre[class*="language-"] code {
  font-size: inherit;
  background: none;
  border: 0;
  padding: 0;
  white-space: pre;
}
.copy-btn {
  /* Sits on the block's top border, like the label, so it never covers code. */
  position: absolute;
  top: 0;
  right: 0.9rem;
  transform: translateY(-50%);
  font: 600 0.75rem/1 var(--font-body);
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}
.copy-btn:hover, .copy-btn:focus-visible { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--accent); }

.token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--tok-comment); font-style: italic; }
.token.keyword, .token.boolean, .token.important, .token.atrule { color: var(--tok-keyword); }
.token.string, .token.char, .token.attr-value, .token.regex, .token.inserted { color: var(--tok-string); }
.token.number, .token.constant, .token.symbol { color: var(--tok-number); }
.token.function, .token.class-name, .token.builtin { color: var(--tok-function); }
.token.property, .token.key, .token.attr-name, .token.tag, .token.table { color: var(--tok-property); }
.token.variable, .token.parameter, .token.assign-left { color: var(--tok-variable); }
.token.punctuation, .token.operator { color: var(--muted); }
.token.bold { font-weight: 700; }

/* ---------- Landing page ---------- */

.hero { padding: 2rem 0 1rem; }
.hero-logo { display: block; width: min(300px, 80%); height: auto; margin: 0 0 1.75rem; }
.hero .pitch { font-size: 1.35rem; line-height: 1.5; margin: 0 0 0.5rem; }
.hero .sub { color: var(--muted); margin: 0 0 2rem; }

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0 0 2.5rem;
}
.btn {
  display: inline-block;
  padding: 0.6rem 1.05rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.primary:hover { filter: brightness(1.08); color: var(--bg); }

.post-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.35rem;
  background: var(--surface);
  margin: 0 0 2rem;
}
.post-card h2 { margin: 0.25rem 0 0.5rem; font-size: 1.35rem; padding: 0; }
.post-card h2 a { color: var(--fg); text-decoration: none; }
.post-card h2 a:hover { color: var(--accent); }
.post-card p { margin: 0 0 0.5rem; }
.post-card .byline { font-size: 0.9rem; }

.facts { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.facts li { margin: 0; padding-left: 1.2rem; position: relative; }
.facts li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.7em;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
}

.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .logo-light { display: none; }
  .logo-dark { display: block; }
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  body { font-size: 1.05rem; }
  .lead { font-size: 1.12rem; }
  h2 { font-size: 1.4rem; margin-top: 2.5rem; }
  main.wrap { padding-top: 1.75rem; }
  .post-header .byline { flex-direction: column; gap: 0; }
  .post-header .byline span + span::before { content: none; }
  .site-nav { gap: 0.8rem; font-size: 0.9rem; }
  pre[class*="language-"] { font-size: 0.8rem; }
  th, td { padding: 0.45rem 0.55rem; }
}

@media print {
  .copy-btn, .site-nav, .toc { display: none; }
  a { color: inherit; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* =====================================================================
   Section-by-section reading mode (posts/introducing-siftwise/*.html)
   ===================================================================== */

:root { --sidebar-w: 17.5rem; }

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 100;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
}
.skip-link:focus { top: 0.75rem; }

/* Thin progress bar along the top edge */
.slide-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
  z-index: 60;
}
.slide-progress > span { display: block; height: 100%; background: var(--accent); }

.slides .site-header { position: sticky; top: 0; z-index: 30; background: var(--bg); }
.slides .site-header .wrap { min-height: 3.25rem; }
.header-tools { display: flex; align-items: center; gap: 0.75rem; font-size: 0.92rem; }
.slide-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.header-tools a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.header-tools a:hover { color: var(--accent); }

.sections-toggle, .sidebar-close {
  font: 600 0.9rem/1 var(--font-body);
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
}
.sections-toggle:hover, .sidebar-close:hover { border-color: var(--accent); color: var(--accent); }

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

/* ---------- Sidebar ---------- */

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem 1.5rem;
  font-size: 0.93rem;
  line-height: 1.45;
  z-index: 50;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.25rem 0 1rem;
}
.sidebar-title { font-weight: 700; color: var(--fg); text-decoration: none; }
.sidebar-title:hover { color: var(--accent); }

.read-status { margin: 0 0 1.1rem; }
.read-status p { margin: 0 0 0.4rem; display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.read-count { font-weight: 600; font-variant-numeric: tabular-nums; }
.read-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.read-bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }
.link-btn {
  font: inherit;
  font-size: 0.85rem;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.section-list { list-style: none; margin: 0; padding: 0; }
.section-list > li { margin: 0.1rem 0; }
.section-list > li > a {
  display: grid;
  grid-template-columns: 1.6rem 1fr 1rem;
  gap: 0.25rem;
  align-items: baseline;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border-left: 3px solid transparent;
  color: var(--fg);
  text-decoration: none;
}
.section-list > li > a:hover { background: var(--bg); color: var(--accent); }
.section-list .num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.section-list .check { color: var(--accent); font-weight: 700; visibility: hidden; }
.section-list > li.is-read .check { visibility: visible; }
.section-list > li > a[aria-current="page"] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 650;
}

.sub-list { list-style: none; margin: 0.15rem 0 0.4rem 2.35rem; padding: 0; border-left: 1px solid var(--border); }
.sub-list li { margin: 0; }
.sub-list a {
  display: block;
  padding: 0.2rem 0.6rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
}
.sub-list a:hover { color: var(--accent); }
.sub-list a.is-active { color: var(--fg); border-left-color: var(--accent); font-weight: 600; }

.sidebar-foot { margin: 1.25rem 0 0; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 0.9rem; }
.sidebar-foot a { display: block; margin: 0.25rem 0; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  z-index: 45;
}
.drawer-backdrop[hidden] { display: none; }

/* Desktop: the sidebar is always there, and the page shifts right. */
@media (min-width: 1024px) {
  body.slides { padding-left: var(--sidebar-w); }
  .slides .sections-toggle, .slides .sidebar-close { display: none; }
  .slides .slide-progress { left: var(--sidebar-w); }
}

/* Phones and tablets: a slide-in drawer. */
@media (max-width: 1023.98px) {
  .sidebar {
    width: min(20rem, 86vw);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    box-shadow: 0 0 32px rgb(0 0 0 / 0.25);
  }
  .sidebar.is-open {
    transform: none;
    visibility: visible;
    transition: transform 0.22s ease, visibility 0s;
  }
  body.drawer-open { overflow: hidden; }
  .header-tools .one-page { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar.is-open, .read-bar > span { transition: none; }
}

/* ---------- Section content ---------- */

.slide h2.sub { font-size: 1.2rem; margin: 2rem 0 0.5rem; padding-top: 0; }
.slides [id] { scroll-margin-top: 4.5rem; }
.slide-end { height: 1px; }

/* Entering a page: a short fade and slide, CSS only. */
@media (prefers-reduced-motion: no-preference) {
  .slides main.wrap { animation: slide-in 0.28s ease-out both; }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Pager ---------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 2.5rem 0 1rem;
}
.pager a, .pager .pager-empty {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
  line-height: 1.35;
}
.pager .pager-empty { visibility: hidden; }
.pager a:hover { border-color: var(--accent); }
.pager a:hover .pager-title { color: var(--accent); }
.pager .pager-next { text-align: right; align-items: flex-end; }
.pager-dir { font-size: 0.85rem; font-weight: 650; color: var(--accent); }
.pager-title { font-weight: 600; font-size: 0.98rem; }
.pager-links { text-align: center; color: var(--muted); font-size: 0.92rem; margin: 0 0 0.5rem; }
.key-hint { color: var(--muted); font-size: 0.85rem; text-align: center; margin: 0 0 1rem; }
@media (hover: none) { .key-hint .keys { display: none; } }
@media (hover: hover) { .key-hint .swipe { display: none; } }

@media (max-width: 600px) {
  .pager { gap: 0.5rem; }
  .pager a, .pager .pager-empty { padding: 0.7rem 0.75rem; }
  .pager-title { font-size: 0.9rem; }
  .header-tools { gap: 0.5rem; }
}

/* ---------- Author ---------- */

.avatar {
  display: block;
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface);
}
.avatar-lg { width: 112px; height: 112px; }

.author-card {
  display: flex;
  gap: 1.1rem;
  align-items: flex-start;
  margin: 3rem 0 1rem;
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1rem;
  line-height: 1.55;
}
.author-card p { margin: 0 0 0.35rem; }
.author-card .author-title {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.2rem;
  padding: 0;
}
.author-card .author-name { font-size: 1.1rem; }
.author-card .author-bio { color: var(--fg); }
.author-card .author-links { margin: 0.5rem 0 0; font-size: 0.95rem; }

.about-hero {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin: 0.5rem 0 1.5rem;
}
.about-hero h1 { margin: 0 0 0.25rem; }
.about-handle { color: var(--muted); margin: 0; }
.site-nav a[aria-current="page"] { color: var(--fg); font-weight: 600; }
.post-card .cta { margin: 1rem 0 0.25rem; }

@media (max-width: 600px) {
  .author-card { flex-direction: column; gap: 0.75rem; padding: 1.1rem; }
  .about-hero { flex-direction: column; align-items: flex-start; gap: 0.9rem; }
  .avatar-lg { width: 96px; height: 96px; }
  .header-tools .about-link { display: none; }
}

/* ---------- Landing page: section cards ---------- */

.landing-h2 { font-size: 1.35rem; margin: 0 0 0.75rem; padding: 0; }
.section-cards {
  list-style: none;
  padding: 0;
  margin: 0 0 2.5rem;
  display: grid;
  gap: 0.6rem;
}
.section-cards li { margin: 0; }
.section-cards a {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: 0.15rem 0.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
}
.section-cards a:hover { border-color: var(--accent); }
.section-cards a:hover .card-title { color: var(--accent); }
.section-cards .num {
  grid-row: span 2;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.section-cards .card-title { font-weight: 650; line-height: 1.35; }
.section-cards .card-desc { color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
