:root {
  --bg: #faf8f3;
  --surface: #fffdf9;
  --ink: #221e18;
  --muted: #787064;
  --faint: #a49b8d;
  --line: #ece5d8;
  --line-strong: #ded4c4;
  --accent: #b4532a;
  --accent-ink: #8f3f1e;
  --accent-soft: #f3e7dc;
  --reading: #302a22;
  --reading-quote: #443b30;
  --shadow: rgba(60, 40, 20, 0.14);
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --maxw: 720px;
}

[data-theme="dark"] {
  --bg: #17140f;
  --surface: #221d16;
  --ink: #ece6da;
  --muted: #a39a89;
  --faint: #756c5d;
  --line: #322c22;
  --line-strong: #443c2f;
  --accent: #e0824f;
  --accent-ink: #ee9a6d;
  --accent-soft: #38281d;
  --reading: #ded7c9;
  --reading-quote: #c7bdac;
  --shadow: rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

a { color: var(--accent); text-decoration: none; transition: color .18s ease; }
a:hover { color: var(--accent-ink); }
img { max-width: 100%; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 62px;
}
.site-header .brand {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.site-header nav a {
  margin-left: 26px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}
.site-header nav a:hover, .site-header nav a.active { color: var(--ink); }
.site-header nav { display: flex; align-items: center; }
.theme-toggle {
  margin-left: 22px;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--line-strong); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* reading progress */
.read-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 30; background: transparent; }
.read-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

main.wrap { padding-top: 40px; padding-bottom: 72px; min-height: 60vh; }

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 44px 0 40px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 52px;
}
.hero .avatar {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 24px;
  display: block;
  border: 4px solid var(--surface);
  box-shadow: 0 8px 30px var(--shadow), 0 0 0 1px var(--line-strong);
}
.hero-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.3rem, 6vw, 3.1rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.hero .tagline {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(1.15rem, 3vw, 1.4rem);
  color: var(--accent);
  margin: 0 0 18px;
}
.hero .bio {
  max-width: 46ch;
  margin: 0 auto 26px;
  color: var(--muted);
  font-size: 1.05rem;
}

/* ---------- Socials ---------- */
.socials { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }
.socials a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color .18s ease, background .18s ease, border-color .18s ease, transform .18s ease;
}
.socials a:hover {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--line-strong);
  transform: translateY(-2px);
}

/* ---------- Section labels ---------- */
.section-label {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--faint);
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.projects { margin-bottom: 56px; }

/* ---------- Projects ---------- */
.project-list { list-style: none; padding: 0; margin: 0; }
.project-list li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  margin: 0 -16px;
  border-radius: 12px;
  transition: background .18s ease;
}
.project-list li:hover { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.project-list .project-logo {
  width: 28px; height: 28px;
  border-radius: 7px;
  flex: none;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.project-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.project-meta a { font-family: var(--display); font-size: 1.15rem; font-weight: 600; color: var(--ink); }
.project-list li:hover .project-meta a { color: var(--accent); }
.project-meta .desc { color: var(--muted); font-size: 0.92rem; }
.project-arrow { color: var(--faint); font-size: 1.1rem; transition: transform .18s ease, color .18s ease; }
.project-list li:hover .project-arrow { color: var(--accent); transform: translate(2px, -2px); }

/* ---------- Essays (year grouped) ---------- */
.year-group {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px 20px;
  padding: 22px 0;
  border-top: 1px solid var(--line);
}
.year-group:first-of-type { border-top: none; padding-top: 4px; }
.year {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--faint);
  padding-top: 10px;
  position: sticky;
  top: 78px;
  align-self: start;
}
.post-list { list-style: none; padding: 0; margin: 0; }
.post-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  padding: 9px 0;
}
.post-list li a {
  font-family: var(--display);
  font-size: 1.16rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--ink);
  transition: color .16s ease;
}
.post-list li a:hover { color: var(--accent); }
.post-list li time {
  font-family: var(--sans);
  color: var(--faint);
  font-size: 0.82rem;
  white-space: nowrap;
  flex: none;
  font-variant-numeric: tabular-nums;
}

/* ---------- Post (reading) ---------- */
.back-link {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 26px;
}
.back-link:hover { color: var(--accent); }
.post h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2rem, 5vw, 2.7rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
}
.post-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--sans);
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 40px;
}
.post-meta .dot { color: var(--faint); }
.post-content {
  font-family: var(--display);
  font-size: 1.2rem;
  line-height: 1.78;
  color: var(--reading);
}
.post-content p { margin: 0 0 1.4em; }
.post-content a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--accent-soft); }
.post-content img { display: block; height: auto; border-radius: 8px; margin: 2em auto; box-shadow: 0 10px 34px var(--shadow); }
.post-content blockquote {
  margin: 1.7em 0;
  padding: 0.4em 0 0.4em 1.4em;
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--reading-quote);
}
.post-content blockquote p { margin: 0.3em 0; }
.post-content ul, .post-content ol { margin: 0 0 1.4em; padding-left: 1.3em; }
.post-content li { margin: 0.45em 0; }
.post-content pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #2b2620;
  color: #f3ede2;
  border-radius: 10px;
  padding: 16px 18px;
  overflow-x: auto;
  margin: 1.6em 0;
  font-size: 0.92rem;
  line-height: 1.55;
}
.post-content code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.post-content > p code, .post-content li code {
  background: var(--accent-soft);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  font-size: 0.86em;
}
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 56px;
}
.post-nav-item a {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.post-nav-item a:hover { border-color: var(--line-strong); background: var(--surface); transform: translateY(-2px); }
.post-nav-item.next { text-align: right; }
.post-nav-label { font-family: var(--sans); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.post-nav-title { font-family: var(--display); font-size: 1.05rem; color: var(--ink); line-height: 1.3; }
.post-nav-item a:hover .post-nav-title { color: var(--accent); }

.post-footer {
  margin-top: 40px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.post-footer .socials { justify-content: flex-end; }

/* ---------- List page ---------- */
.page-title { font-family: var(--display); font-weight: 600; font-size: 2.2rem; margin: 0 0 28px; letter-spacing: -0.02em; }
.pager { display: flex; justify-content: space-between; font-family: var(--sans); font-size: 0.92rem; margin-top: 32px; }

/* ---------- Newsletter ---------- */
.newsletter {
  margin: 56px 0 8px;
  padding: 34px 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: center;
}
.nl-heading { font-family: var(--display); font-weight: 600; font-size: 1.5rem; letter-spacing: -0.01em; margin: 0 0 8px; }
.nl-blurb { color: var(--muted); font-size: 0.98rem; max-width: 42ch; margin: 0 auto 20px; }
.nl-form { display: flex; gap: 10px; max-width: 440px; margin: 0 auto; }
.nl-input {
  flex: 1; min-width: 0;
  font-family: var(--sans); font-size: 0.98rem;
  padding: 12px 15px;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: 10px;
  transition: border-color .18s ease;
}
.nl-input:focus { outline: none; border-color: var(--accent); }
.nl-btn {
  font-family: var(--sans); font-size: 0.95rem; font-weight: 600;
  padding: 12px 22px;
  color: #fff; background: var(--accent);
  border: none; border-radius: 10px; cursor: pointer;
  transition: background .18s ease, transform .18s ease;
}
.nl-btn:hover { background: var(--accent-ink); transform: translateY(-1px); }
.nl-success { color: var(--accent); font-family: var(--sans); font-weight: 500; margin: 16px 0 0; }
@media (max-width: 640px) {
  .newsletter { padding: 26px 20px; }
  .nl-form { flex-direction: column; }
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 36px 0 48px;
}
.site-footer .wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.site-footer .copyright { margin: 0; font-family: var(--sans); color: var(--faint); font-size: 0.85rem; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .hero { padding-top: 28px; }
  .post-content { font-size: 1.1rem; }
  .year-group { grid-template-columns: 1fr; gap: 4px; }
  .year { position: static; padding-top: 0; margin-bottom: 4px; }
  .post-list li { gap: 12px; }
  .post-footer { flex-direction: column; align-items: flex-start; }
  .post-footer .socials { justify-content: flex-start; }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav-item.next, .post-nav-item.next a { text-align: left; }
}
