/* ============ tokens ============ */
:root {
  --blue: #1d82f5;
  --blue-d: #0f62cc;
  --blue-soft: #edf5ff;
  --ink: #0f1115;
  --ink-2: #2b2f36;
  --muted: #6b7079;
  --line: #e6e8eb;
  --soft: #f5f6f8;
  --paper: #fff;
  --card: #fff;
  --code-ink: #b4361f;
  color-scheme: light;
  --serif: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --frame: 0px;
}
[data-theme="dark"] {
  --blue: #3d95ff;
  --blue-d: #7ab6ff;
  --blue-soft: #14243a;
  --ink: #eef0f3;
  --ink-2: #c8ccd3;
  --muted: #8d939c;
  --line: #262a31;
  --soft: #16191e;
  --paper: #0e1013;
  --card: #16191e;
  --code-ink: #ff9e80;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { overscroll-behavior: none; -webkit-text-size-adjust: 100%; scroll-padding-top: 24px; }
body { overscroll-behavior: none; margin: 0; background: var(--paper); color: var(--ink-2); font: 400 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
img { display: block; max-width: 100%; }
a { color: inherit; }
::selection { background: var(--blue); color: #fff; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
button { font: inherit; }
.wrap { width: min(1240px, 100% - 48px); margin-inline: auto; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 50; background: var(--ink); color: #fff; padding: 10px 14px; text-decoration: none; }
.skip:focus { top: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============ type ============ */
.display { font: 400 clamp(40px, 5vw, 68px)/0.98 var(--serif); letter-spacing: -0.02em; color: var(--ink); margin: 0; }
.display em { font-style: italic; }
.display.xl { font-size: clamp(54px, 8vw, 108px); line-height: 0.92; letter-spacing: -0.025em; }
.display.sm { font-size: clamp(40px, 4.6vw, 64px); }
.light { color: #fff; }
.lede { font-size: 18px; line-height: 1.6; color: var(--muted); max-width: 560px; margin: 22px auto 0; }
.lede.left { margin-left: 0; }
.kicker { font: 500 12.5px/1.4 var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 14px; }
.kicker.light { color: rgba(255, 255, 255, 0.85); }

/* ============ buttons / tags ============ */
.empty { color: var(--muted); font-style: italic; }

/* ============ nav ============ */
.nav { position: absolute; z-index: 10; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 26px 0; color: #fff; text-shadow: 0 1px 14px rgba(0, 0, 0, .35); }
.brand { font: 400 30px/1 var(--serif); letter-spacing: -0.01em; color: #fff; text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 30px; }
.nav-link { color: rgba(255, 255, 255, .82); text-decoration: none; font-size: 15px; font-weight: 500; transition: color .2s; }
.nav-link:hover, .nav-link[aria-current] { color: #fff; }
.nav-link[aria-current] { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; }
.theme { width: 36px; height: 36px; margin-right: -8px; border: 0; background: transparent; color: rgba(255, 255, 255, .82); cursor: pointer; display: grid; place-items: center; transition: color .2s; }
.theme:hover { color: #fff; }
.theme svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; filter: drop-shadow(0 1px 8px rgba(0, 0, 0, .35)); }
.theme .sun, [data-theme="dark"] .theme .moon { display: none; }
[data-theme="dark"] .theme .sun { display: block; }
[data-theme="dark"] .banner-img { filter: brightness(.82); }

/* ============ torn paper ============ */
.tear { position: relative; filter: drop-shadow(0 22px 34px rgba(8, 28, 70, .35)); }
.tear-rough { position: absolute; inset: 0; filter: url(#rough); }
.tear-rough.soft { filter: url(#rough-soft); }
.tear-paper { position: absolute; inset: 0; background: radial-gradient(closest-side, #fbf9f4 70%, #e4e0d6 100%); }
.tear-img { position: absolute; inset: 0; overflow: hidden; background: #3b2a1e; }
.tear-img img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.12); transition: transform .9s cubic-bezier(.2, .7, .2, 1); }
.tear-img::after { content: ""; position: absolute; inset: 0; background: radial-gradient(closest-side, transparent 62%, rgba(30, 16, 6, .5) 100%); pointer-events: none; }
.edge { position: absolute; left: -2%; right: -2%; height: 92px; z-index: 4; filter: url(#rough) drop-shadow(0 6px 8px rgba(0, 0, 0, .22)); pointer-events: none; }
.edge > div { position: absolute; inset: 0; background: var(--paper); }
.edge.at-top { top: -26px; }
.edge.at-bottom { bottom: -26px; filter: url(#rough) drop-shadow(0 -6px 8px rgba(0, 0, 0, .18)); }
.rough-soft { filter: url(#rough-soft); }

/* ============ page banners ============ */
.page-banner { position: relative; margin: var(--frame); height: clamp(400px, 62vh, 620px); overflow: hidden; background: #24324d; }
.page-banner::after { content: ""; position: absolute; inset: 0; z-index: 1; background: linear-gradient(to top, rgba(0, 0, 0, .62), rgba(0, 0, 0, 0) 58%), linear-gradient(to bottom, rgba(0, 0, 0, .28), transparent 30%); pointer-events: none; }
.banner-img, .banner-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.banner-title { position: absolute; z-index: 3; left: 0; right: 0; bottom: 96px; }
.post-banner { height: clamp(320px, 50vh, 500px); }
.banner-title > * { animation: fade-up .9s cubic-bezier(.2, .7, .2, 1) both; }
.banner-title > :nth-child(2) { animation-delay: .08s; }
.banner-title > :nth-child(3) { animation-delay: .16s; }
.banner-img { animation: settle 1.6s cubic-bezier(.2, .7, .2, 1) both; }
.banner-lede { margin: 20px 0 0; max-width: 520px; font-size: 18px; line-height: 1.5; color: rgba(255, 255, 255, .88); }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } }
@keyframes settle { from { opacity: 0; transform: scale(1.06); } }

/* ============ writeups list ============ */
.list-page { padding: 32px 0 120px; }
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin: 24px 0 28px; }
.search { display: flex; align-items: center; gap: 10px; width: min(280px, 100%); height: 44px; padding: 0 14px; border: 1px solid var(--line); background: var(--paper); transition: border-color .2s, box-shadow .2s; }
.search:focus-within { border-color: var(--ink); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; font: 15px var(--sans); color: var(--ink); background: transparent; }
.rows { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 200px; gap: 36px; padding: 34px 0; border-bottom: 1px solid var(--line); animation: fade-up .6s cubic-bezier(.2, .7, .2, 1) both; }
.row time { font: 500 13px/1 var(--mono); color: var(--muted); padding-top: 12px; }
.row h2 { font: 400 clamp(26px, 2.8vw, 36px)/1.08 var(--serif); letter-spacing: -0.01em; margin: 0 0 10px; color: var(--ink); }
.row h2 a { text-decoration: none; }
.row h2 a:hover { color: var(--blue); }
.row p { margin: 0; color: var(--muted); max-width: 640px; }
.row-art { aspect-ratio: 3 / 2; overflow: hidden; background: var(--soft); align-self: start; }
.row-art img { width: 100%; height: 100%; object-fit: cover; transition: transform .6s cubic-bezier(.2, .7, .2, 1); }
.row:hover .row-art img { transform: scale(1.06); }

/* ============ post ============ */
.post-page { padding-bottom: 120px; }
.post-head { max-width: 860px; padding: 40px 0 44px; margin-left: calc(220px + 64px); }
.back { display: inline-block; margin-bottom: 26px; font-size: 14px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--blue); }
.post-title { font-size: clamp(40px, 5.2vw, 70px); line-height: 1; }
.post-head .lede { margin-top: 18px; }
.post-grid { display: grid; grid-template-columns: 220px minmax(0, 780px); gap: 64px; }
.post-body { grid-column: 2; min-width: 0; }
.toc { position: sticky; top: 28px; align-self: start; max-height: calc(100vh - 56px); overflow: auto; padding-left: 18px; border-left: 1px solid var(--line); font-size: 14px; }
.toc-h { font: 500 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0 16px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 10px; line-height: 1.4; }
.toc li.l3 { padding-left: 14px; font-size: 13.5px; }
.toc a { color: var(--muted); text-decoration: none; transition: color .2s; }
.toc a:hover, .toc a.on { color: var(--blue); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 80px; }
.pg { display: block; padding-top: 18px; border-top: 1px solid var(--line); text-decoration: none; }
.pg:hover span { color: var(--blue); }
.pg small { display: block; font: 500 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.pg span { font: 400 22px/1.15 var(--serif); color: var(--ink); }
.pg.r { text-align: right; }

/* prose */
.prose { font-size: 17.5px; line-height: 1.78; color: var(--ink-2); overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 22px; }
.prose h2, .prose h3, .prose h4 { position: relative; color: var(--ink); scroll-margin-top: 24px; }
.prose h2 { font: 400 clamp(32px, 3.4vw, 42px)/1.1 var(--serif); letter-spacing: -0.01em; margin: 64px 0 18px; }
.prose h3 { font: 600 20px/1.3 var(--sans); letter-spacing: -0.01em; margin: 40px 0 12px; }
.prose h4 { font: 600 17px/1.3 var(--sans); margin: 32px 0 10px; }
.anchor { margin-left: 10px; color: var(--blue); text-decoration: none; opacity: 0; transition: opacity .2s; font-family: var(--sans); font-weight: 400; font-size: .7em; }
.prose :is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; }
.prose a:not(.anchor) { color: var(--blue-d); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.prose a:not(.anchor):hover { color: var(--blue); }
.prose strong { color: var(--ink); font-weight: 600; }
.prose :not(pre) > code { font: 500 .84em var(--mono); font-variant-ligatures: none; background: var(--soft); border: 1px solid var(--line); padding: .12em .4em; border-radius: 4px; color: var(--code-ink); overflow-wrap: anywhere; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 22px; }
.prose li { margin: 6px 0; }
.prose li > ul, .prose li > ol { margin: 6px 0 0; }
.prose li::marker { color: var(--blue); }
.prose li.task { list-style: none; margin-left: -1.4em; }
.prose blockquote { margin: 30px 0; padding: 18px 24px; border-left: 3px solid var(--blue); background: var(--blue-soft); color: var(--ink-2); }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: 0; margin: 52px 0; text-align: center; height: auto; }
.prose hr::after { content: "⁂"; color: #a5aab2; font-size: 24px; }
.prose figure { margin: 34px 0; }
.prose figure img, .prose p img { border: 1px solid var(--line); margin-inline: auto; }
.prose figcaption { margin-top: 10px; text-align: center; font-size: 14px; color: var(--muted); font-style: italic; }
.table { overflow-x: auto; margin: 28px 0; border: 1px solid var(--line); }
.prose table { border-collapse: collapse; width: 100%; font-size: 15px; }
.prose th, .prose td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.prose th { background: var(--soft); font-weight: 600; color: var(--ink); }
.prose tr:last-child td { border-bottom: 0; }

/* code */
.code { margin: 30px 0; background: #0f1420; border: 1px solid #1d2433; border-radius: 6px; overflow: hidden; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 8px 16px; background: #151b2a; border-bottom: 1px solid #1d2433; font: 500 12px/1 var(--mono); color: #8b95a8; text-transform: lowercase; }
.copy { background: transparent; border: 1px solid #2b3447; color: #c9d1e0; font: 500 12px/1 var(--mono); padding: 6px 10px; border-radius: 4px; cursor: pointer; transition: background .2s, border-color .2s; }
.copy:hover { background: #2b3447; border-color: #3a455c; color: #fff; }
.code pre { margin: 0; padding: 18px 20px; overflow-x: auto; }
.code code { font: 400 14px/1.65 var(--mono); color: #dbe2ef; tab-size: 4; font-variant-ligatures: none; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag { color: #ff9e80; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #b5e48c; }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: #f7c873; }
.hljs-comment, .hljs-quote { color: #6b7690; font-style: italic; }
.hljs-title, .hljs-section, .hljs-title.function_ { color: #7cc4ff; }
.hljs-attr, .hljs-attribute, .hljs-selector-attr, .hljs-selector-class, .hljs-selector-id { color: #ffb86c; }
.hljs-built_in, .hljs-type, .hljs-title.class_ { color: #7ee0c3; }
.hljs-meta, .hljs-meta .hljs-keyword { color: #8be9fd; }
.hljs-tag, .hljs-name { color: #ff9e80; }
.hljs-variable, .hljs-template-variable, .hljs-params { color: #e6ebf5; }
.hljs-deletion { color: #ff6b6b; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ============ about ============ */
.about-page { padding: 56px 0 120px; }
.about-grid { display: grid; grid-template-columns: 280px minmax(0, 720px); gap: 72px; }
.portrait { aspect-ratio: 1; overflow: hidden; background: var(--soft); position: sticky; top: 28px; }
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.about-copy .lede { font: 400 clamp(28px, 3vw, 36px)/1.2 var(--serif); color: var(--ink); max-width: none; margin: 0 0 28px; }

/* ============ responsive ============ */
@media (max-width: 1080px) {
  .post-head { margin-left: 0; }
  .post-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .post-body { grid-column: 1; }
  .toc { position: static; max-height: none; border: 0; border-block: 1px solid var(--line); padding: 20px 0 12px; margin-bottom: 44px; }
}
@media (max-width: 900px) {
  .row { grid-template-columns: minmax(0, 1fr) 120px; gap: 10px 22px; }
  .row time { grid-column: 1 / -1; padding: 0; }
  .about-grid { grid-template-columns: minmax(0, 1fr); gap: 36px; }
  .portrait { position: static; width: 180px; }
}
@media (max-width: 600px) {
  .wrap { width: calc(100% - 36px); }
  .nav { padding: 18px 0; }
  .brand { font-size: 26px; }
  .nav-links { gap: 20px; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .row-art { display: none; }
  .prose { font-size: 16.5px; }
  .code { margin-inline: -18px; border-radius: 0; border-inline: 0; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .banner-title { bottom: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
