/* Gradient: the post index and the reading page.
   Same Apple light/dark system as the main site; a narrow measure and roomy
   type for long-form reading. */
:root {
  --bg: #fff; --band: #f5f5f7;
  --ink: #1d1d1f; --body: #333336; --soft: #6e6e73; --faint: #86868b;
  --line: #d2d2d7; --hair: rgba(0,0,0,.08);
  --accent: #0071e3; --accent-ink: #0066cc;
  --code-bg: #f5f5f7; --code-ink: #1d1d1f;
  /* syntax colours */
  --hl-kw: #ad3da4; --hl-str: #c41a16; --hl-num: #1c00cf; --hl-com: #8a8a8e; --hl-fn: #326d74; --hl-ty: #3900a0; --hl-attr: #836c28;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Helvetica Neue", Arial, sans-serif;
  --text: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.28,.11,.32,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000; --band: #1c1c1e;
    --ink: #f5f5f7; --body: #d1d1d6; --soft: #a1a1a6; --faint: #86868b;
    --line: #38383a; --hair: rgba(255,255,255,.1);
    --accent: #2997ff; --accent-ink: #2997ff;
    --code-bg: #1c1c1e; --code-ink: #f5f5f7;
    --hl-kw: #ff7ab2; --hl-str: #ff8170; --hl-num: #d9c97c; --hl-com: #7f8c98; --hl-fn: #67b7a4; --hl-ty: #dabaff; --hl-attr: #ffa14f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000; --band: #1c1c1e;
  --ink: #f5f5f7; --body: #d1d1d6; --soft: #a1a1a6; --faint: #86868b;
  --line: #38383a; --hair: rgba(255,255,255,.1);
  --accent: #2997ff; --accent-ink: #2997ff;
  --code-bg: #1c1c1e; --code-ink: #f5f5f7;
  --hl-kw: #ff7ab2; --hl-str: #ff8170; --hl-num: #d9c97c; --hl-com: #7f8c98; --hl-fn: #67b7a4; --hl-ty: #dabaff; --hl-attr: #ffa14f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.47 var(--text); letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
::selection { background: rgba(0,113,227,.18); }

/* ---- floating glass top bar (matches the main nav) ---- */
.bar { position: fixed; top: 12px; left: 0; right: 0; z-index: 50; width: calc(100% - 24px); max-width: 760px; height: 52px;
  margin: 0 auto; border-radius: 26px; display: flex; align-items: center; gap: 12px; padding: 0 8px 0 20px;
  background: linear-gradient(180deg, rgba(255,255,255,.5), rgba(255,255,255,.22));
  -webkit-backdrop-filter: blur(9px) saturate(200%) brightness(1.06); backdrop-filter: blur(9px) saturate(200%) brightness(1.06);
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.95), inset 0 -1px 1px rgba(255,255,255,.35), inset 0 0 0 .5px rgba(0,0,0,.05),
    0 10px 30px -6px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.05);
  transition: transform .5s var(--ease), opacity .35s var(--ease); }
.bar.hide { transform: translateY(calc(-100% - 20px)); opacity: 0; }
.bar.hide:focus-within { transform: none; opacity: 1; }
.back { display: inline-flex; align-items: center; gap: 5px; color: var(--accent-ink); font-size: 16px; padding: 9px 14px;
  margin-left: -10px; border-radius: 980px; transition: transform .45s var(--spring), background .2s; }
.back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .back:hover { transform: scale(1.06); background: rgba(120,120,128,.12); } }
.theme-toggle { margin-left: auto; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; background: none; color: var(--ink);
  transition: transform .45s var(--spring), background .2s; }
.theme-toggle:hover, .theme-toggle:focus-visible { background: rgba(120,120,128,.16); transform: scale(1.12); }
.theme-toggle svg { width: 18px; height: 18px; fill: currentColor; }
.theme-toggle .ic-sun { display: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---- page ---- */
.wrap { max-width: 704px; margin: 0 auto; padding: 128px 22px 96px; }
.empty { color: var(--soft); }

/* ---- index ---- */
.hero { margin-bottom: 48px; }
.hero h1 { font: 600 clamp(40px, 6vw, 56px)/1.05 var(--display); letter-spacing: -0.015em; margin: 0; }
.sub { color: var(--soft); font: 400 clamp(19px, 2.2vw, 21px)/1.4 var(--display); margin: 10px 0 0; }
.posts { list-style: none; margin: 0; padding: 0; }
.posts .year { font: 600 14px/1 var(--text); color: var(--faint); letter-spacing: 0; padding: 32px 0 10px; border-bottom: 1px solid var(--hair); }
.posts .year:first-child { padding-top: 0; }
.row { display: grid; grid-template-columns: 1fr auto; column-gap: 24px; row-gap: 4px; padding: 16px 0; border-bottom: 1px solid var(--hair); }
.row .t { font: 500 19px/1.35 var(--display); color: var(--ink); transition: color .2s; }
.row time { font: 400 15px/1.6 var(--text); color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .s { grid-column: 1 / -1; font-size: 15px; color: var(--soft); }
.row:hover .t, .row:focus-visible .t { color: var(--accent-ink); }

/* ---- post ---- */
.post-head { margin-bottom: 40px; }
.post-head h1 { font: 700 clamp(34px, 5.4vw, 48px)/1.1 var(--display); letter-spacing: -0.02em; margin: 0; text-wrap: balance; }
.meta { font-size: 15px; color: var(--faint); margin: 14px 0 0; letter-spacing: -0.01em; }

/* ---- tags ---- */
.tags { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; padding: 0; }
.tag { display: inline-block; padding: 4px 10px; border-radius: 980px; background: var(--band); color: var(--soft);
  font: 500 13px/1.3 var(--text); letter-spacing: -0.005em; transition: color .15s, background .15s; }
a.tag:hover, a.tag:focus-visible { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 12%, var(--band)); }
.post-foot { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--hair); }
.post-foot .tags { margin: 0; }
.post-foot:has(.tags:empty) { display: none; }
.filter { margin: 18px 0 0; font-size: 15px; color: var(--soft); }
.filter .tag { margin: 0 4px; color: var(--ink); }
.filter a { color: var(--accent-ink); }
.filter a:hover { text-decoration: underline; }

/* ---- prose ---- */
.prose { font-size: 19px; line-height: 1.68; color: var(--body); letter-spacing: -0.012em; overflow-wrap: break-word; }
.prose > * { margin: 0 0 1.25em; }
.prose > :last-child { margin-bottom: 0; }
.prose h2, .prose h3, .prose h4 { position: relative; color: var(--ink); font-family: var(--display); letter-spacing: -0.015em; scroll-margin-top: 90px; }
.prose h2 { font-size: 28px; line-height: 1.2; font-weight: 600; margin: 2em 0 .6em; }
.prose h3 { font-size: 22px; line-height: 1.3; font-weight: 600; margin: 1.7em 0 .5em; }
.prose h4 { font-size: 19px; font-weight: 600; margin: 1.5em 0 .4em; }
.prose .anchor { margin-left: .35em; color: var(--faint); font-weight: 400; opacity: 0; transition: opacity .15s; }
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose h4:hover .anchor, .prose .anchor:focus-visible { opacity: 1; }
.prose a { color: var(--accent-ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--accent-ink) 35%, transparent); transition: text-decoration-color .2s; }
.prose a:hover { text-decoration-color: currentColor; }
.prose h2 a.anchor, .prose h3 a.anchor, .prose h4 a.anchor { text-decoration: none; color: var(--faint); }
.prose strong { color: var(--ink); font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: .35em 0; }
.prose li::marker { color: var(--faint); }
.prose blockquote { margin-left: 0; padding: 2px 0 2px 20px; border-left: 3px solid var(--line); color: var(--soft); font-style: italic; }
.prose hr { border: 0; height: 1px; background: var(--hair); margin: 2.5em 0; }
.prose img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 12px; }
.prose figure { margin-left: 0; margin-right: 0; }
.prose figcaption { margin-top: 10px; font-size: 15px; color: var(--faint); text-align: center; }

/* code */
.prose code { font: .86em/1.5 var(--mono); letter-spacing: 0; background: var(--code-bg); color: var(--code-ink); padding: .12em .38em; border-radius: 6px; }
.prose .codeblock { position: relative; margin-left: -16px; margin-right: -16px; }
.prose pre { margin: 0; padding: 18px 20px; background: var(--code-bg); border-radius: 14px; overflow-x: auto; }
.copy { position: absolute; top: 8px; right: 8px; display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px;
  font: 500 12px/1 var(--text); letter-spacing: 0; color: var(--soft); background: var(--bg); border: 1px solid var(--hair);
  border-radius: 8px; cursor: pointer; opacity: 0; transition: opacity .15s, color .15s; }
.copy svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.codeblock:hover .copy, .copy:focus-visible, .copy.done { opacity: 1; }
.copy:hover { color: var(--ink); }
.copy.done { color: var(--accent-ink); }
@media (hover: none), (max-width: 640px) { .copy { display: none; } }   /* phones: no copy button */
.prose pre code { display: block; padding: 0; background: none; font-size: 15px; line-height: 1.6; tab-size: 4; }
.hljs-keyword, .hljs-built_in, .hljs-literal, .hljs-meta .hljs-keyword { color: var(--hl-kw); }
.hljs-string, .hljs-regexp, .hljs-template-tag { color: var(--hl-str); }
.hljs-number, .hljs-symbol { color: var(--hl-num); }
.hljs-comment, .hljs-quote { color: var(--hl-com); font-style: italic; }
.hljs-title.function_, .hljs-title { color: var(--hl-fn); }
.hljs-type, .hljs-title.class_, .hljs-class .hljs-title { color: var(--hl-ty); }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-params, .hljs-variable, .hljs-meta { color: var(--hl-attr); }
.hljs-params { color: inherit; }
.hljs-addition { color: #1f8a3b; } .hljs-deletion { color: #c41a16; }

/* tables */
.prose table { width: 100%; border-collapse: collapse; font-size: 16px; display: block; overflow-x: auto; }
.prose th, .prose td { padding: 9px 14px; border-bottom: 1px solid var(--hair); white-space: nowrap; }
.prose th:not([align]), .prose td:not([align]) { text-align: left; }
.prose th { color: var(--ink); font-weight: 600; border-bottom-color: var(--line); }
.prose td { font-variant-numeric: tabular-nums; }

/* math */
.prose .math-block { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.prose .katex { font-size: 1.08em; }

/* ---- dark: glass bar ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bar { background: linear-gradient(180deg, rgba(44,44,48,.55), rgba(22,22,24,.38)); border-color: rgba(255,255,255,.12);
    box-shadow: inset 0 1px 1px rgba(255,255,255,.18), inset 0 -1px 1px rgba(255,255,255,.05), 0 10px 30px -6px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.4); }
  :root:not([data-theme="light"]) .theme-toggle .ic-moon { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .ic-sun { display: block; }
}
:root[data-theme="dark"] .bar { background: linear-gradient(180deg, rgba(44,44,48,.55), rgba(22,22,24,.38)); border-color: rgba(255,255,255,.12);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.18), inset 0 -1px 1px rgba(255,255,255,.05), 0 10px 30px -6px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.4); }
:root[data-theme="dark"] .theme-toggle .ic-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .ic-sun { display: block; }

/* ---- phone ---- */
@media (max-width: 640px) {
  .bar { top: 8px; width: calc(100% - 16px); height: 50px; border-radius: 22px; padding: 0 8px 0 16px; }
  .wrap { padding: 100px 16px 72px; }
  .prose { font-size: 18px; }
  .prose pre { border-radius: 0; padding: 16px; }
  .prose pre code { font-size: 14px; }
  .row { grid-template-columns: 1fr; }
  .row time { order: -1; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
