:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #666666;
  --link: #0a66c2;
  --border: #e5e7eb;
  --code-bg: #f6f8fa;
  --code-text: #0b1021;
  /* Syntax token colors (light) */
  --code-keyword: #d73a49;
  --code-string: #22863a;
  --code-comment: #6a737d;
  --code-number: #005cc5;

  --font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --container: 72ch;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0d0f;
    --text: #f5f5f5;
    --muted: #b0b0b0;
    --link: #6fb2ff;
    --border: #1f2937;
    --code-bg: #111318;
    --code-text: #e6e6e6;
  }
}

html[data-theme="dark"] {
  --bg: #0c0d0f;
  --text: #f5f5f5;
  --muted: #b0b0b0;
  --link: #6fb2ff;
  --border: #1f2937;
  --code-bg: #111318;
  --code-text: #e6e6e6;
  /* Syntax token colors (dark) */
  --code-keyword: #ff7b72;
  --code-string: #7ee787;
  --code-comment: #8b949e;
  --code-number: #79c0ff;
}


/* Additional themes */
html[data-theme="cappuccino"] {
  --bg: #f6f0e9;
  --text: #1f1b16;
  --muted: #6e6256;
  --link: #8a4b2e; /* warm cappuccino accent with AA contrast */
  --border: #e2d8cc;
  --code-bg: #f1e7dc;
  --code-text: #2b2118;
  --font-sans: 'Lora', Georgia, Cambria, "Times New Roman", Times, serif;
}
/* Cappuccino-specific link refinements */
html[data-theme="cappuccino"] a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.16em;
  text-decoration-thickness: 0.09em;
  text-decoration-color: color-mix(in oklab, var(--link), transparent 35%);
}
html[data-theme="cappuccino"] a:hover {
  color: color-mix(in oklab, var(--link), var(--text) 14%);
  text-decoration-thickness: 0.12em;
}
html[data-theme="cappuccino"] a:visited {
  color: color-mix(in oklab, var(--link), var(--text) 22%);
}

html[data-theme="candy"] {
  --bg: #fff5f9;
  --text: #141014;
  --muted: #6b6066;
  --link: #b80f52; /* vivid but accessible on light bg */
  --border: #f0d6e1;
  --code-bg: #ffeaf2;
  --code-text: #2b1020;
  --font-sans: 'Nunito', ui-rounded, "SF Pro Rounded", "Trebuchet MS", Verdana, "Segoe UI", system-ui, sans-serif;
}

html[data-theme="darker"] {
  --bg: #0a0b0d;
  --text: #e9e9e9;
  --muted: #b8b8b8;
  --link: #72b0ff;
  --border: #171a1f;
  --code-bg: #0e1015;
  --code-text: #e2e2e2;
}


/* Force light theme when explicitly selected, even if OS prefers dark */
html[data-theme="light"] {
  --bg: #ffffff;
  --text: #111111;
  --muted: #666666;
  --link: #0a66c2;
  --border: #e5e7eb;
  --code-bg: #f6f8fa;
  --code-text: #0b1021;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-size: clamp(16px, 15px + 0.25vw, 18px);
}

/* Wrap all content so theme radio overrides can cascade */
.page {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { width: min(var(--container), 100% - 2rem); margin: 0 auto; padding: 0 var(--space-4); }

.site-header {
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  backdrop-filter: saturate(180%) blur(10px);
  background-color: color-mix(in oklab, var(--bg), transparent 10%);
  z-index: 10;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) 0;
}
.brand .site-name {
  font-weight: 700;
  font-size: 18px;
  margin-right: var(--space-3);
}
.brand .tagline {
  color: var(--muted);
  font-size: 12px;
}
.nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}
.nav-link { color: var(--text); }
.nav-link:hover { color: var(--link); }
/* Burger menu control (hidden on wide screens) */
.menu-toggle { display: none; }
.menu-toggle { border: 1px solid var(--border); background: color-mix(in oklab, var(--bg), var(--text) 6%); color: var(--text); border-radius: 8px; padding: 6px 10px; }
.menu-bars { display: inline-block; width: 20px; height: 2px; background: var(--text); position: relative; vertical-align: middle; }
.menu-bars::before, .menu-bars::after { content: ""; position: absolute; left: 0; width: 20px; height: 2px; background: var(--text); }
.menu-bars::before { top: -6px; }
.menu-bars::after { top: 6px; }

/* Theme select control */
.theme-select {
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg), var(--text) 6%);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  min-height: 36px;
}

.content { padding: var(--space-6) 0; }
.page > main { flex: 1 0 auto; }

/* Home hero (About + image) */
.home-hero {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-5);
  align-items: center;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--bg), var(--text) 4%);
}
.home-hero .hero-media img {
  display: block;
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--border);
}
.home-title { margin-top: var(--space-6); }

@media (max-width: 640px) {
  .home-hero { grid-template-columns: 1fr; }
  .home-hero .hero-media img { width: 96px; height: 96px; }
}

/* Breadcrumbs */
.breadcrumbs { color: var(--muted); font-size: 14px; margin: var(--space-2) 0 var(--space-4); }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--text); text-decoration: underline; }
.breadcrumbs .crumb-home { font-family: var(--font-mono); }

h1, h2, h3 { line-height: 1.2; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.25rem); margin: var(--space-5) 0 var(--space-3); }
h2 { font-size: clamp(1.5rem, 1.1rem + 1.2vw, 1.75rem); margin: var(--space-4) 0 var(--space-2); }
h3 { font-size: clamp(1.25rem, 1.05rem + 0.6vw, 1.375rem); margin: var(--space-3) 0 var(--space-2); }
p { margin: var(--space-3) 0; }

/* Horizontal rule: nicer Markdown `---` separator */
.post-content hr,
.page-content hr,
.home hr,
.home-about hr {
  /* Layout */
  --hr-gap: 18px;          /* vertical gap reserved for the ornament */
  --hr-color: color-mix(in oklab, var(--text), var(--bg) 85%);
  border: 0;
  height: var(--hr-gap);
  width: 100%;
  max-width: 64ch;
  margin: clamp(var(--space-5), 4vh, var(--space-6)) auto;
  background: none;
  position: relative;
}
.post-content hr::before,
.page-content hr::before,
.home hr::before,
.home-about hr::before {
  /* The rule line */
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%; transform: translateY(-50%);
  height: 1px;
  background: linear-gradient(
    to right,
    transparent,
    var(--hr-color),
    color-mix(in oklab, var(--hr-color), transparent 20%),
    var(--hr-color),
    transparent
  );
}
.post-content hr::after,
.page-content hr::after,
.home hr::after,
.home-about hr::after {
  /* Center ornament – improves visual scanning between sections */
  content: "✦"; /* safe, readable glyph */
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: var(--muted);
  background: var(--bg);
  padding: 0 0.5rem;
  line-height: 1;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
}
/* Optional variant: add class="ornament" to <hr> to switch glyph */
.post-content hr.ornament::after,
.page-content hr.ornament::after,
.home hr.ornament::after,
.home-about hr.ornament::after { content: "\2022\00A0\2022\00A0\2022"; } /* • • • */
pre, code { font-family: var(--font-mono); }
pre {

  display: inline-block;
  color: var(--muted);
  background: var(--bg);
  padding: 0 0.5rem;
  transform: translateY(-0.6rem);
}

pre, code { font-family: var(--font-mono); }
pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: var(--space-4);
  border-radius: var(--radius);
  overflow: auto;
  border: 1px solid var(--border);
}
code { background: color-mix(in oklab, var(--code-bg), transparent 30%); padding: 2px 4px; border-radius: 4px; }
/* Minimal syntax highlighting */
pre code .tok-k { color: var(--code-keyword); }
pre code .tok-s { color: var(--code-string); }
pre code .tok-c { color: var(--code-comment); font-style: italic; }
pre code .tok-n { color: var(--code-number); }

blockquote {
  border-left: 3px solid var(--border);
  margin: var(--space-4) 0;
  padding-left: var(--space-4);
  color: var(--muted);
}

.post-header { margin-bottom: var(--space-5); }
.post-title { margin: 0 0 var(--space-2); }
.post-meta { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.post-meta .dot { opacity: 0.5; }
.tags { display: inline-flex; gap: 6px; }
.tag { padding: 2px 6px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: var(--muted); }

.post-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-4); }
.post-list li { padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.post-list a { font-weight: 600; }
.post-list .excerpt { color: var(--muted); font-size: 14px; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  padding: var(--space-5) 0;
  margin-top: auto;
}

/* Post prev/next navigation */
.post-nav { display: grid; grid-template-columns: 1fr; gap: var(--space-4); margin-top: var(--space-6); }
@media (min-width: 768px) {
  .post-nav { grid-template-columns: 1fr 1fr; }
  /* Pin cards to columns so Newer stays on the right even alone */
  .post-nav .nav-card.older { grid-column: 1; }
  .post-nav .nav-card.newer { grid-column: 2; }
}
.nav-card { display: block; border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); background: color-mix(in oklab, var(--bg), var(--text) 4%); text-decoration: none; color: inherit; }
.nav-card:hover { background: color-mix(in oklab, var(--bg), var(--text) 8%); }
.nav-kicker { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.nav-title { display: block; font-weight: 700; margin-bottom: 6px; }
.nav-excerpt { display: block; color: var(--muted); font-size: 14px; }

/* Utility */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* Accessibility: focus styles, skip link, responsive media */
:where(a, button, [role="button"], input, select, textarea):focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

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

.skip-link {
  position: absolute;
  left: 0;
  top: -40px;
  background: var(--bg);
  color: var(--text);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.skip-link:focus { top: 8px; left: 8px; z-index: 100; }

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* Responsive nav: collapse to burger on small screens */
@media (max-width: 768px) {
  .site-header .container { flex-wrap: wrap; gap: var(--space-3); }
  .menu-toggle { display: inline-block; }
  .nav { display: none; width: 100%; flex-direction: column; gap: 0; padding-top: var(--space-2); }
  #nav-toggle:checked ~ .nav { display: flex; }
  .nav-link { padding: 8px 0; }
  /* Theme select: improve usability on small screens */
  label.theme-label.sr-only {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
    margin: 8px 0 4px !important;
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
    border: 0 !important;
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
  }
  .theme-select {
    width: 100%;
    font-size: 16px; /* avoid iOS zoom on focus */
    padding: 10px 12px;
    min-height: 44px; /* comfortable touch target */
  }
}

/* Print optimizations for printable pages */
@media print {
  .site-header, .site-footer, nav, .theme-select { display: none !important; }
  .container { width: 100% !important; padding: 0 12mm; }
  a { color: #000 !important; text-decoration: none; }
  body { background: #fff !important; color: #000 !important; }
  .btn-print { display: none !important; }
}

/* Page header layout and print button styles */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.btn-print {
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg), var(--text) 6%);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  cursor: pointer;
}
.btn-print:hover { background: color-mix(in oklab, var(--bg), var(--text) 10%); }
.btn-print:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.footer-links { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.footer-links a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
