:root,
html[data-theme="light"] {
  --text: #1a1a1a;
  --muted: #5a5a5a;
  --accent: #1f3a93;
  --amber: #b45309;
  --ink: #0e1116;
  --rule: #e3e3e3;
  --bg: #fff;
  --surface: #fafafa;
  --code-bg: #f4f4f5;
  --code-panel: #f7f7f8;
  --code-toolbar: #efeff1;
  --mark-bg: #fef3c7;
  --preview-bg: #fff7ed;
  --preview-border: #fdba74;
  --preview-text: #9a3412;
  --toggle-hover: #f1f1f1;
  --display: "Inter Tight", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --measure: 880px;
}

html[data-theme="dark"] {
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #8ab4f8;
  --amber: #e8a45c;
  --ink: #f1f3f4;
  --rule: #2a2f36;
  --bg: #12151a;
  --surface: #0b0d10;
  --code-bg: #1a1f27;
  --code-panel: #161b22;
  --code-toolbar: #1c222b;
  --mark-bg: #5c4a1f;
  --preview-bg: #2a2118;
  --preview-border: #8a5a2b;
  --preview-text: #f0c48a;
  --toggle-hover: #1c222b;
}

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

html {
  background: var(--surface);
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  font-family: var(--display);
  text-wrap: balance;
}

p,
blockquote {
  text-wrap: pretty;
}

a {
  color: var(--accent);
}

a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  color: #fff;
}

.skip-link:focus {
  left: 0.75rem;
  top: 0.75rem;
}

.preview-banner {
  max-width: var(--measure);
  margin: 0.75rem auto 0;
  padding: 0.55rem 1.25rem;
  background: var(--preview-bg);
  border: 1px solid var(--preview-border);
  border-radius: 6px;
  color: var(--preview-text);
  font-size: 0.9rem;
}

/* ——— Header / nav ——— */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}

.site-header-bar {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 3.25rem;
}

.site-header .brand {
  font-family: var(--display);
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  letter-spacing: -0.01em;
  font-size: 0.92rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-end {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.nav-icon-btn:hover,
.nav-icon-btn.is-active {
  color: var(--ink);
  background: var(--toggle-hover);
  border-color: var(--rule);
}

.nav-icon-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.nav-search-form {
  display: none;
  align-items: center;
  gap: 0.15rem;
  margin-right: 0.15rem;
}

.nav-search-form input[type="search"] {
  width: 11rem;
  max-width: 28vw;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
}

.nav-search-form input[type="search"]::placeholder {
  color: var(--muted);
}

.nav-search-form input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
}

.nav-menu-toggle .icon-close {
  display: none;
}

.nav-menu-toggle[aria-expanded="true"] .icon-menu {
  display: none;
}

.nav-menu-toggle[aria-expanded="true"] .icon-close {
  display: block;
}

html[data-theme="light"] .theme-toggle .icon-sun,
html[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-moon,
html[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

.nav-drawer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-top: 1px solid var(--rule);
}

.nav-drawer[hidden] {
  display: none;
}

.nav-drawer a {
  display: block;
  padding: 0.7rem 0.35rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 1rem;
  border-radius: 6px;
}

.nav-drawer a:hover,
.nav-drawer a.is-active {
  color: var(--ink);
  background: var(--toggle-hover);
}

.nav-drawer-search {
  font-weight: 600;
}

@media (min-width: 720px) {
  .nav-search-form {
    display: flex;
  }

  .nav-drawer-search {
    display: none;
  }

  .site-header-bar {
    padding: 0.85rem 1.25rem;
  }

  .site-header .brand {
    font-size: 1.05rem;
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header {
    background: var(--bg);
  }
}

/* ——— Shared labels / footer ——— */

.section-label {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 1.25rem;
  color: var(--amber);
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.site-footer {
  max-width: var(--measure);
  margin: clamp(3rem, 8vw, 4.5rem) auto 0;
  padding: 0 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer .section-label {
  margin-bottom: 0.75rem;
}

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

.site-footer a:hover {
  color: var(--accent);
}

.site-footer .copyright {
  margin: 1.5rem 0 0;
}

.muted {
  color: var(--muted);
}

/* ——— Home / index ——— */

.blog-index {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1.75rem, 4vw, 2.5rem) 1.25rem 1rem;
}

.blog-index .intro {
  padding: 0 0 clamp(2rem, 5vw, 3rem);
}

.blog-index .intro h1 {
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  margin: 0 0 1rem;
  letter-spacing: -0.035em;
  line-height: 1;
  font-weight: 700;
  color: var(--ink);
}

.blog-index .lede {
  font-size: clamp(1.05rem, 2vw, 1.2rem);
  color: var(--muted);
  margin: 0;
  line-height: 1.55;
  max-width: 36em;
}

.blog-index section + section {
  margin-top: clamp(2.5rem, 6vw, 3.5rem);
}

.blog-index .section-label {
  margin-bottom: 0.5rem;
}

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

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

.post-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  padding: 1.1rem 0;
  text-decoration: none;
  color: inherit;
}

.post-list h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  transition: color 0.15s ease;
}

.post-list a:hover h3 {
  color: var(--amber);
}

.post-list .desc {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 38em;
}

.post-list time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 560px) {
  .post-list a {
    flex-direction: column;
    gap: 0.35rem;
  }

  .post-list time {
    order: -1;
  }
}

/* ——— Post / page ——— */

.post {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1.75rem, 4vw, 2.5rem) 1.25rem 2rem;
}

.post .back {
  margin: 0 0 1rem;
}

.post .back a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.post .back a:hover {
  color: var(--accent);
}

.post header h1 {
  font-size: 2rem;
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-weight: 700;
}

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

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: -1rem 0 2rem;
}

.post-tag {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  text-decoration: none;
}

a.post-tag:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: clamp(2rem, 5vw, 3rem);
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
}

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

.pagination .disabled {
  color: var(--muted);
  opacity: 0.5;
}

.pagination .page-status {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ——— Prose ——— */

.prose {
  font-size: 1.05rem;
}

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

.prose p {
  line-height: 1.7;
  margin: 0 0 1.25rem;
}

.prose a {
  color: var(--accent);
}

.prose a.external-link .external-link-icon {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-left: 0.2em;
  vertical-align: -0.05em;
  opacity: 0.65;
}

.prose a.external-link:hover .external-link-icon {
  opacity: 1;
}

.prose h2 {
  font-size: 1.45rem;
  margin: 2.5rem 0 0.75rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.prose h3 {
  font-size: 1.15rem;
  margin: 2rem 0 0.5rem;
  color: var(--ink);
}

.prose h4,
.prose h5,
.prose h6 {
  margin: 1.5rem 0 0.4rem;
  color: var(--ink);
}

.prose ul,
.prose ol {
  margin: 0 0 1.25rem;
  padding-left: 1.35rem;
}

.prose li {
  line-height: 1.7;
  margin: 0.25rem 0;
}

.prose li > ul,
.prose li > ol {
  margin: 0.35rem 0;
}

.prose ul.contains-task-list {
  list-style: none;
  padding-left: 0;
}

.prose .task-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.prose .task-list-item input {
  margin-top: 0.45rem;
  pointer-events: none;
  cursor: default;
}

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

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

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

.prose code {
  font-family: var(--mono);
  font-size: 0.88em;
}

.prose :not(pre) > code {
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.prose pre {
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--code-bg);
  margin: 0 0 1.35rem;
}

.prose .code-block {
  margin: 0 0 1.35rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: var(--code-panel);
}

.prose .code-block-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  border-bottom: 1px solid var(--rule);
  background: var(--code-toolbar);
  font-size: 0.72rem;
}

.prose .code-block-lang {
  margin-right: auto;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--muted);
}

.prose .code-copy {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.2rem;
  border-radius: 4px;
  line-height: 0;
  cursor: pointer;
}

.prose .code-copy .code-copy-check {
  display: none;
}

.prose .code-copy.is-copied {
  color: #2f9e44;
}

.prose .code-copy.is-copied .code-copy-icon {
  display: none;
}

.prose .code-copy.is-copied .code-copy-check {
  display: block;
}

.prose .code-block pre {
  margin: 0;
  border-radius: 0;
  background: transparent;
}

.prose .code-block pre.hljs {
  background: transparent;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--rule);
}

.prose figure {
  margin: 2rem 0;
}

.prose figure img {
  display: block;
  margin: 0 auto;
}

.prose figcaption {
  margin-top: 0.6rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  margin: 0 0 1.35rem;
}

.prose th,
.prose td {
  border: 1px solid var(--rule);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.prose th {
  background: var(--code-panel);
  font-weight: 600;
}

.prose .heading-anchor {
  color: var(--rule);
  text-decoration: none;
  margin-right: 0.35rem;
  font-weight: 400;
}

.prose .heading-anchor:hover {
  color: var(--amber);
}

.prose mark {
  background: var(--mark-bg);
  padding: 0.05em 0.15em;
}

html[data-theme="dark"] .hljs {
  background: transparent;
  color: #e6edf3;
}

html[data-theme="dark"] .hljs-comment,
html[data-theme="dark"] .hljs-quote {
  color: #8b949e;
}

html[data-theme="dark"] .hljs-keyword,
html[data-theme="dark"] .hljs-selector-tag,
html[data-theme="dark"] .hljs-doctag {
  color: #ff7b72;
}

html[data-theme="dark"] .hljs-string,
html[data-theme="dark"] .hljs-attr {
  color: #a5d6ff;
}

html[data-theme="dark"] .hljs-number,
html[data-theme="dark"] .hljs-literal {
  color: #79c0ff;
}

html[data-theme="dark"] .hljs-title,
html[data-theme="dark"] .hljs-section {
  color: #d2a8ff;
}

@media print {
  .site-header,
  .site-footer,
  .preview-banner,
  .post .back,
  .theme-toggle,
  .nav-menu-toggle,
  .nav-search-form,
  .nav-drawer {
    display: none;
  }

  html,
  body {
    background: #fff;
    color: #000;
  }

  .post {
    max-width: none;
    padding: 0;
  }
}

/* ——— Search ——— */

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

.nav-search {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
}

.nav-search:hover,
.nav-search.active {
  color: var(--accent);
}

.search-page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.error-page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.error-code {
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.error-header h1 {
  margin: 0 0 0.5rem;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
}

.error-header .lede {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0;
}

.error-actions a {
  color: var(--accent);
}

.search-header h1 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
}

.search-header .lede {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-form input[type="search"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg-elevated, transparent);
  color: var(--text);
}

.search-form button {
  font: inherit;
  padding: 0.65rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.search-status {
  min-height: 1.4em;
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

.search-result {
  padding: 1.1rem 0;
  border-top: 1px solid var(--rule);
}

.search-result a {
  text-decoration: none;
  color: inherit;
}

.search-result h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  color: var(--ink, var(--text));
}

.search-result .desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.search-result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-top: 0.55rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.search-result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.search-result-tags li {
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
}
