/* ---------- Tokens ---------- */
:root {
  --bg: #fdfdfc;
  --bg-rgb: 253, 253, 252;
  --fg: #111;
  --muted: rgba(0, 0, 0, 0.4);
  --border: #f2f2f2;
  --border-strong: #ededed;
  --link-underline: #d9d9d9;
  --link-underline-hover: #666;
  --selection-bg: #ededed;
  --focus-color: rgba(0, 122, 255, 0.5);
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-mono: "SF Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  --indent: 6.75rem;
  --quote-fg: rgba(17, 17, 17, 0.6);
  --quote-bar: #e6e6e6;
  --code-bg: rgba(0, 0, 0, 0.04);
  --code-fg: rgba(0, 0, 0, 0.75);
  --pre-bg: #f8f8f8;
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1c1b;
  --bg-rgb: 28, 28, 27;
  --fg: #e2e2df;
  --muted: rgba(226, 226, 223, 0.48);
  --border: #2c2c2a;
  --border-strong: #383835;
  --link-underline: #464642;
  --link-underline-hover: #969690;
  --selection-bg: #32322f;
  --quote-fg: rgba(226, 226, 223, 0.65);
  --quote-bar: #3d3d3a;
  --code-bg: rgba(255, 255, 255, 0.07);
  --code-fg: rgba(226, 226, 223, 0.85);
  --pre-bg: #242422;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-weight: inherit; font-size: inherit; }

html { background: var(--bg); color: var(--fg); scroll-behavior: smooth; }
body {
  min-height: 100vh;
  overflow-y: scroll;
  font-family: var(--font-sans);
  font-size: 16px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--selection-bg); color: var(--fg); }
:focus-visible { outline: 2px solid var(--focus-color); border-radius: 2px; }

/* ---------- Layout ---------- */
.container { max-width: 36.375rem; margin: 0 auto; padding: 5rem 1rem 2.5rem; }
.container::before {
  content: "";
  position: fixed; top: 0; left: 0; right: 0; height: 8rem;
  pointer-events: none; z-index: 9;
  background: linear-gradient(180deg, rgba(var(--bg-rgb), 1) 0%, rgba(var(--bg-rgb), 0.74) 19%, rgba(var(--bg-rgb), 0.38) 47%, rgba(var(--bg-rgb), 0.13) 73%, rgba(var(--bg-rgb), 0) 100%);
}
@media (max-width: 768px) {
  .container { padding: 2rem 1.5rem 2.5rem; }
  .container::before { height: 2.5rem; }
}

/* ---------- Article ---------- */
.article { max-width: 70ch; }
.article > header { display: flex; flex-direction: column; gap: 0.25rem; padding-bottom: 0.5rem; }
.article > header h1 { font-size: 0.875rem; font-weight: 500; line-height: 1.25rem; letter-spacing: -0.00563rem; }
.article > header time { font-size: 0.875rem; line-height: 1.25rem; font-weight: 460; letter-spacing: -0.00563rem; color: var(--muted); }
.article p, .article li { font-size: 0.875rem; font-weight: 460; line-height: 1.35rem; letter-spacing: -0.00563rem; }
.article > p { padding-top: 1rem; }
.article em { font-family: var(--font-serif); font-style: italic; font-size: 0.9375rem; font-weight: 430; letter-spacing: 0.01rem; }
.article blockquote { padding: 2rem 0; font-size: 0.8125rem; font-style: italic; line-height: 1.4; color: var(--quote-fg); }
.article blockquote p { position: relative; padding: 0 0 0 1rem; }
.article blockquote p::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 0.125rem; border-radius: 5px; background: var(--quote-bar); }
.article code { font-family: var(--font-mono); font-size: 0.8125rem; padding: 0.1rem 0.25rem; border-radius: 0.25rem; background: var(--code-bg); color: var(--code-fg); }
.article pre { margin-top: 1rem; padding: 0.875rem 1rem; border-radius: 0.5rem; background: var(--pre-bg); overflow-x: auto; }
.article pre code { padding: 0; background: none; }

.back-link { display: inline-block; margin-bottom: 2rem; font-size: 0.875rem; font-weight: 460; letter-spacing: -0.00563rem; color: var(--muted); transition: color 0.2s ease; }
.back-link:hover { color: var(--fg); }

/* ---------- Inline link ---------- */
.basic-link { position: relative; display: inline; }
.basic-link::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  border-radius: 2px; background: var(--link-underline); pointer-events: none;
  transition: background-color 0.2s ease;
}
.basic-link:hover::before { background: var(--link-underline-hover); }

/* ---------- Writing list ---------- */
.post-list { padding-top: 3rem; }
.post-list-title {
  font-size: 0.875rem; font-weight: 460; letter-spacing: -0.00563rem;
  color: var(--muted); padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.year { position: relative; border-bottom: 1px solid var(--border); }
.year:last-child { border-bottom: 0; }
.year-label {
  position: absolute; left: 0; top: 0.735rem;
  font-size: 0.875rem; font-weight: 460; letter-spacing: -0.00563rem;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.post-link {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.735rem 0 0.735rem var(--indent);
}
.post-link::after {
  content: ""; position: absolute; left: var(--indent); right: 0; bottom: 0;
  border-bottom: 1px solid var(--border);
}
.year li:last-child .post-link::after { display: none; }
.post-title, .post-link time {
  font-size: 0.875rem; font-weight: 460; letter-spacing: -0.00563rem;
  transition: opacity 0.14s ease;
}
.post-title { color: var(--fg); }
.post-link time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (min-width: 521px) {
  .post-list:hover .post-link .post-title,
  .post-list:hover .post-link time { opacity: 0.3; }
  .post-list .post-link:hover .post-title,
  .post-list .post-link:hover time { opacity: 1; }
}
@media (max-width: 520px) {
  :root { --indent: 3rem; }
}

/* ---------- Footer ---------- */
.site-footer { padding: 2.5rem 0 5rem; }
.site-footer::before { content: ""; display: block; width: 3.125rem; height: 1px; background: var(--border-strong); margin-bottom: 2.375rem; }
.site-footer .row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.site-footer p { font-size: 0.8125rem; font-weight: 460; letter-spacing: -0.0025rem; color: var(--muted); }
.site-footer a { transition: color 0.2s ease; }
.site-footer .footer-links { display: flex; align-items: center; gap: 1rem; }
.site-footer a:hover { color: var(--fg); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  position: fixed; top: 1.5rem; right: 1.5rem; z-index: 10;
  width: 2rem; height: 2rem; display: grid; place-items: center;
  background: none; border: 0; border-radius: 6px; cursor: pointer;
  color: var(--muted); transition: color 0.2s ease;
}
.theme-toggle:hover { color: var(--fg); }
.theme-toggle svg { width: 15px; height: 15px; transition: transform 0.25s ease; }
html[data-theme="dark"] .theme-toggle svg { transform: rotate(180deg); }
@media (max-width: 768px) { .theme-toggle { right: 1.25rem; } }

/* ---------- Theme switch: directional wipe ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }
html[data-theme="light"]::view-transition-new(root) { animation: revealDown 0.45s cubic-bezier(0.22, 1, 0.36, 1) both; }
html[data-theme="dark"]::view-transition-new(root) { animation: revealUp 0.45s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes revealDown { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes revealUp { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0 0 0 0); } }

/* ---------- Entrance ---------- */
@keyframes staggerIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.article > *, .post-list, .site-footer { animation: staggerIn 0.5s ease both; }
.article > :nth-child(2) { animation-delay: 0.05s; }
.article > :nth-child(3) { animation-delay: 0.1s; }
.article > :nth-child(4) { animation-delay: 0.15s; }
.article > :nth-child(5) { animation-delay: 0.2s; }
.article > :nth-child(n+6) { animation-delay: 0.25s; }
.post-list { animation-delay: 0.3s; }
.site-footer { animation-delay: 0.4s; }
@media (prefers-reduced-motion: reduce) {
  .article > *, .post-list, .site-footer { animation: none; }
  html { scroll-behavior: auto; }
  html[data-theme="light"]::view-transition-new(root),
  html[data-theme="dark"]::view-transition-new(root) { animation: none; }
}
