:root {
  --bg: #ffffff;
  --fg: #0b0c0d;
  --muted: #4b5563; /* darker for contrast */
  --link: #0b5fff;
  --link-visited: #0b5fff; /* tweak for contrast */
  --card: #f3f4f6;
  --border: #d1d5db;
  --accent: #0077ff; /* stronger accent */
  --code-bg: #f1f5f9; /* slate-50 */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c10;
    --fg: #e7eaf0;
    --muted: #a5adba; /* brighter muted */
    --link: #74b0ff; /* brighter for contrast */
    --link-visited: #74b0ff;
    --card: #111318;
    --border: #2a3441;
    --accent: #60a5fa; /* stronger accent */
    --code-bg: #1b1f27; /* deeper to contrast text */
  }
}

/* System font stacks (pref order: Apple → Microsoft → Android → Linux → fallbacks) */
:root {
  --font-sans:
    -apple-system, system-ui, "Segoe UI", Roboto, Ubuntu, Cantarell,
    "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "DejaVu Sans Mono", monospace;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: var(--font-sans), serif;
  background: var(--bg);
  color: var(--fg);
  font-size: clamp(1rem, 0.9rem + 0.35vw, 1.125rem);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img {
  max-width: 100%;
  height: auto;
}
/* Reset default figure margins */
figure {
  margin: 0;
}
a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
a:visited {
  color: var(--link-visited);
}

.container {
  max-width: 70ch;
  margin: 0 auto;
}
.skip-link {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  width: auto;
  height: auto;
  background: var(--card);
  color: var(--fg);
  padding: 0.5rem 0.75rem;
  border-radius: 0.25rem;
  outline: 2px solid var(--accent);
}

.site-header {
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  backdrop-filter: saturate(180%) blur(10px);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  min-height: 72px;
}
.site-title {
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: clamp(1.6rem, 1rem + 3.2vw, 3.2rem);
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.site-avatar {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  object-fit: cover;
  filter: grayscale(100%);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  min-height: 56px;
}
.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.site-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 1.25rem;
}

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
}
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
}
.footer-inner .social {
  list-style: none;
  display: flex;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
}
h1 {
  font-size: clamp(2rem, 2vw + 1.5rem, 2.6rem);
}
h2 {
  font-size: clamp(1.6rem, 1.8vw + 0.8rem, 2rem);
}
h3 {
  font-size: clamp(1.25rem, 1.2vw + 0.6rem, 1.5rem);
}
.muted {
  color: var(--muted);
}
.tag {
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.9rem;
}

.post-list {
  margin: 1.25rem 0 0;
  padding: 0;
}
.post-list > li {
  list-style: none;
}
.post-card {
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  margin-bottom: 1em;
}
.post-title {
  margin: 0;
}
.summary {
  margin: 0.5rem 0 0;
  flex-grow: 1;
}

.post-header {
  margin: 2rem 0 1.25rem;
}
.post-content {
  margin-top: 1.25rem;
}
.post-content p {
  text-wrap: pretty;
}
.post-content pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow: auto;
  border-radius: 0.375rem;
  font-size: 0.95em;
  line-height: 1.5;
  position: relative;
  color: var(--fg);
}
.post-content :not(pre) > code {
  font-family: var(--font-mono), monospace;
  background: color-mix(in oklab, var(--code-bg) 90%, transparent);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
}
.post-content code {
  font-family: var(--font-mono), monospace;
}
.post-content pre code {
  background: none; /* let Hugo highlighter style colors */
  padding: 0;
  border-radius: 0;
  display: block;
  white-space: pre;
  color: inherit;
}

.post-content pre code.language-markdown,
.post-content pre code[data-lang="markdown"] {
  /* Wrap markdown code blocks to avoid horizontal scrolling */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.post-content :is(h2, h3) {
  margin-top: 2.25rem;
}

.prose p {
  margin: 1rem 0;
}
.prose ul,
.prose ol {
  padding-left: 1.25rem;
}
.prose blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
}
.post-content img,
.prose img {
  border-radius: 0.375rem;
  margin: 1rem 0;
}
/* Render hook figure wrapper */
.md-image {
  margin: 1rem 0;
}
.md-image img {
  display: block;
  max-width: 100%;
  height: auto;
}
.md-image figcaption {
  color: var(--muted);
  font-size: 0.95em;
  margin-top: 0.5rem;
}
.post-content table,
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95em;
}
.post-content table :is(th, td),
.prose table :is(th, td) {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
}
.post-content hr,
.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* About page */
.about-hero {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  align-items: start;
  margin: 1.5rem 0 2.5rem;
}
.about-hero > * {
  align-self: start;
}
.about-left {
  display: flex;
  flex-direction: column;
  align-items: start;
  text-align: center;
  gap: 1rem;
}
.about-right {
  align-self: start;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  margin-top: -1em;
}
.about-name {
  margin: 0.25rem 0 0;
  font-size: clamp(1.6rem, 1.2rem + 2vw, 2.25rem);
}
.avatar-lg {
  width: clamp(180px, 24vw, 260px);
  height: clamp(180px, 24vw, 260px);
  border-radius: 1rem;
  object-fit: cover;
  border: 1px solid var(--border);
  filter: grayscale(100%);
}
.about-left .links {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  gap: 1rem;
}
.about-left .links a {
  color: var(--fg);
  display: inline-flex;
}
.about-right .about-bio {
  max-width: 60ch;
}
.latest-posts {
  margin-top: 2rem;
}
.latest-posts h2 {
  font-size: clamp(1.4rem, 1rem + 1.5vw, 1.8rem);
}
.latest-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: grid;
  gap: 0.75rem;
}

/* Code block with copy button */
.code-block {
  position: relative;
}
.code-block pre {
  margin: 0;
  position: relative;
  z-index: 1;
}
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  color: var(--fg);
  padding: 0;
  border-radius: 0.375rem;
  font: inherit;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  transition:
    opacity 0.15s ease,
    background-color 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease;
}
.code-block:hover .copy-btn,
.code-block:focus-within .copy-btn {
  opacity: 0.92;
  pointer-events: auto;
}
.copy-btn .copy-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.copy-btn::before {
  content: "";
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>')
    no-repeat center;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>')
    no-repeat center / contain;
}
.copy-btn:hover,
.copy-btn:focus-visible {
  opacity: 1;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.copy-btn.copied {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.copy-btn.copied::before {
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6L9 17l-5-5"/></svg>')
    no-repeat center;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6L9 17l-5-5"/></svg>')
    no-repeat center / contain;
}
@media (hover: none) {
  .copy-btn {
    opacity: 0.92;
    pointer-events: auto;
  }
}

/* Better focus visibility */
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 0.125rem;
}
