/* Site styles — homepage + /articles. */

:root {
  --paper: #f6f7f8;
  --ink: #14161a;
  --body: #2b2f35;
  --graphite: #5c626b;
  --rule: #dcdfe3;
  --grid: rgba(37, 70, 216, 0.07);
  --accent: #2546d8;
  --accent-soft: rgba(37, 70, 216, 0.08);
  --code-bg: #eceef1;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --gutter: 40px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss02";
  overflow-x: hidden;
}

::selection {
  background: var(--accent);
  color: #fff;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.mono {
  font-family: var(--mono);
}

/* ── Shell / header / footer ───────────────────────────────── */

.shell {
  width: min(100% - 2 * var(--gutter), 1200px);
  min-height: 100svh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.site-header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--rule);
}

.logo {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.logo span {
  color: var(--accent);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 28px;
  font-size: 14px;
}

.site-nav a {
  color: var(--graphite);
  transition: color 0.15s ease;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
}

.site-nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 8px;
}

.site-nav .location {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--graphite);
}

.site-footer {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--rule);
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 12px;
}

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

/* ── Homepage ──────────────────────────────────────────────── */

.intro {
  position: relative;
  align-self: center;
  margin-block: 56px;
  padding: clamp(40px, 6vw, 80px) clamp(24px, 4vw, 56px);
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(48px, 7vw, 96px);
  align-items: center;
  /* engineering grid */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
  border: 1px solid rgba(37, 70, 216, 0.1);
  animation: settle 0.6s ease-out both;
}

.intro:has(.recent) {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
}

/* registration crosshairs at the grid's four corners */
.intro::before,
.intro::after,
.intro-copy::before,
.intro-copy::after {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  background:
    linear-gradient(var(--accent), var(--accent)) center / 1px 100% no-repeat,
    linear-gradient(var(--accent), var(--accent)) center / 100% 1px no-repeat;
  opacity: 0.55;
}

.intro::before {
  top: -7px;
  left: -7px;
}

.intro::after {
  top: -7px;
  right: -7px;
}

.intro-copy::before {
  bottom: -7px;
  left: -7px;
}

.intro-copy::after {
  bottom: -7px;
  right: -7px;
}

.intro-copy {
  min-width: 0;
}

/* corner marks are positioned against .intro, not .intro-copy */
.intro-copy {
  position: static;
}

h1.name {
  font-size: clamp(56px, 8vw, 104px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.bio {
  max-width: 34em;
  margin-top: 28px;
  color: var(--body);
  font-size: clamp(17px, 1.45vw, 19px);
  line-height: 1.65;
}

.links {
  display: flex;
  gap: 8px;
  margin-top: 36px;
}

.links a {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--graphite);
  transition: color 0.15s ease, border-color 0.15s ease;
}

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

.links svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.links img {
  width: 20px;
  height: 20px;
  display: block;
  filter: grayscale(1) opacity(0.5);
}

.links a:hover img {
  filter: none;
}

/* Recent writing (homepage) */

.recent {
  align-self: center;
  background: var(--paper);
  border: 1px solid var(--rule);
}

.recent-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
  font-weight: 500;
}

.recent-head a {
  color: var(--accent);
  font-weight: 400;
}

.recent-head a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.recent ol {
  list-style: none;
}

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

.recent li a {
  display: block;
  padding: 14px 16px 16px;
  transition: background 0.15s ease;
}

.recent li a:hover {
  background: var(--accent-soft);
}

.recent-meta {
  display: flex;
  gap: 12px;
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 12px;
}

.recent-title {
  display: block;
  margin-top: 6px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.recent li a:hover .recent-title {
  color: var(--accent);
}

/* ── Type labels (essay / note) ────────────────────────────── */

.type {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--graphite);
}

.type-essay-label {
  color: var(--accent);
}

.draft {
  margin-left: 8px;
  padding: 1px 6px;
  border: 1px dashed currentColor;
  color: #a15c00;
  font-family: var(--mono);
  font-size: 11px;
  font-style: normal;
  font-weight: 400;
  vertical-align: middle;
}

/* ── Writing index ─────────────────────────────────────────── */

.writing {
  width: min(100%, 860px);
  padding: 72px 0 112px;
}

.page-head h1 {
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
}

.lede {
  max-width: 34em;
  margin-top: 20px;
  color: var(--body);
  font-size: 18px;
  line-height: 1.6;
}

.filters {
  display: inline-flex;
  margin-top: 48px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}

.filters button {
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--graphite);
  font: 400 14px var(--sans);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.filters button + button {
  border-left: 1px solid var(--rule);
}

.filters button span {
  margin-left: 6px;
  font-family: var(--mono);
  font-size: 12px;
  opacity: 0.7;
}

.filters button:hover {
  color: var(--ink);
}

.filters button[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
}

.archive {
  margin-top: 32px;
}

.year {
  display: grid;
  grid-template-columns: 88px 1fr;
  border-top: 1px solid var(--ink);
}

.year-label {
  padding-top: 22px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
}

.entries {
  list-style: none;
}

.entry + .entry a {
  border-top: 1px solid var(--rule);
}

.entry a {
  display: grid;
  grid-template-columns: 104px 1fr 56px;
  gap: 20px;
  align-items: baseline;
  padding: 20px 0 22px;
}

.entry time {
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.entry-title {
  display: block;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.015em;
  transition: color 0.15s ease;
}

.entry a:hover .entry-title {
  color: var(--accent);
}

.entry-summary {
  display: block;
  margin-top: 6px;
  color: var(--graphite);
  font-size: 15px;
  line-height: 1.6;
}

.entry .type {
  text-align: right;
}

.empty {
  margin-top: 48px;
  padding: 40px;
  border: 1px dashed var(--rule);
  color: var(--graphite);
  font-size: 16px;
  text-align: center;
}

/* ── Article ───────────────────────────────────────────────── */

.article-wrap {
  width: min(100%, 680px);
  margin-inline: auto;
  padding: 64px 0 96px;
}

.back {
  color: var(--graphite);
  font-size: 14px;
  transition: color 0.15s ease;
}

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

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 40px;
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 13px;
}

.article-head h1 {
  margin-top: 14px;
  font-size: clamp(34px, 5vw, 48px);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.type-note .article-head h1 {
  font-size: clamp(30px, 4.2vw, 40px);
}

.article:lang(zh) .article-head h1 {
  letter-spacing: 0;
  line-height: 1.3;
}

.prose {
  margin-top: 36px;
  padding-top: 32px;
  border-top: 1px solid var(--rule);
  color: var(--body);
  font-size: 18px;
  line-height: 1.75;
  text-wrap: pretty;
}

.article:lang(zh) .prose {
  font-size: 17px;
  line-height: 1.95;
  letter-spacing: 0.02em;
}

.prose > * + * {
  margin-top: 1.1em;
}

.prose h2,
.prose h3,
.prose h4 {
  color: var(--ink);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.prose h2 {
  margin-top: 2em;
  font-size: 1.45em;
}

.prose h3 {
  margin-top: 1.8em;
  font-size: 1.2em;
}

.prose h4 {
  margin-top: 1.6em;
  font-size: 1em;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(37, 70, 216, 0.35);
  text-underline-offset: 0.2em;
  transition: text-decoration-color 0.15s ease;
}

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

.prose strong {
  color: var(--ink);
  font-weight: 600;
}

.prose blockquote {
  margin-block: 1.6em;
  padding: 2px 0 2px 1.1em;
  border-left: 2px solid var(--accent);
  color: var(--graphite);
}

.prose blockquote > * + * {
  margin-top: 0.8em;
}

.prose ul,
.prose ol {
  padding-left: 1.5em;
}

.prose li + li {
  margin-top: 0.4em;
}

.prose ol li::marker {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--accent);
}

.prose ul li::marker {
  color: var(--accent);
}

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

.prose img,
.prose video {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  border: 1px solid var(--rule);
}

.prose p:has(> img:only-child) {
  margin-block: 2em;
}

.prose code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.85em;
}

.prose pre {
  margin-block: 1.6em;
  padding: 18px 20px;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  background: var(--code-bg);
  font-size: 14px;
  line-height: 1.6;
}

.prose pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.prose table {
  display: block;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.prose th,
.prose td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}

.prose th {
  border-bottom-color: var(--ink);
  font-weight: 600;
}

.signoff {
  margin-top: 48px;
  color: var(--graphite);
  font-size: 16px;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 64px;
  border: 1px solid var(--rule);
}

.pager a {
  display: block;
  padding: 16px 18px;
  transition: background 0.15s ease;
}

.pager a:hover {
  background: var(--accent-soft);
}

.pager-next {
  grid-column: 2;
  text-align: right;
  border-left: 1px solid var(--rule);
}

.pager span {
  display: block;
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 12px;
}

.pager strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.35;
}

/* ── Motion ────────────────────────────────────────────────── */

@keyframes settle {
  from {
    opacity: 0;
    background-size: 22px 22px;
  }
  to {
    opacity: 1;
    background-size: 24px 24px;
  }
}

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

/* ── Mobile ────────────────────────────────────────────────── */

@media (max-width: 768px) {
  :root {
    --gutter: 16px;
  }

  .site-header {
    height: 60px;
  }

  .site-nav {
    gap: 18px;
  }

  .site-nav .location {
    display: none;
  }

  .intro,
  .intro:has(.recent) {
    align-self: start;
    grid-template-columns: 1fr;
    gap: 40px;
    margin-block: 24px 40px;
    padding: 32px 20px;
  }

  h1.name {
    font-size: clamp(48px, 14vw, 72px);
  }

  .bio {
    margin-top: 20px;
    font-size: 16px;
  }

  .links {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    margin-top: 28px;
  }

  .links a {
    width: 100%;
  }

  .writing {
    padding: 44px 0 72px;
  }

  .lede {
    font-size: 16px;
  }

  .filters {
    margin-top: 36px;
  }

  .year {
    grid-template-columns: 1fr;
  }

  .year-label {
    padding-top: 16px;
  }

  .entry a {
    grid-template-columns: 1fr auto;
    gap: 6px 12px;
    padding: 16px 0 18px;
  }

  .entry time {
    grid-row: 1;
  }

  .entry .type {
    grid-row: 1;
    grid-column: 2;
  }

  .entry-main {
    grid-column: 1 / -1;
  }

  .entry-title {
    font-size: 18px;
  }

  .article-wrap {
    padding: 36px 0 64px;
  }

  .meta {
    margin-top: 28px;
  }

  .prose {
    font-size: 17px;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager-next {
    grid-column: 1;
    border-left: 0;
    border-top: 1px solid var(--rule);
  }
}
