:root {
  --bg: #faf9f5;
  --surface: #f0eee6;
  --surface-code: #f5f3ec;
  --surface-hover: #ebe8de;
  --fg: #141413;
  --fg-prose: #2b2a27;
  --muted: #6e6c64;
  --border: #e5e2d7;
  --accent: #c96442;
  --accent-soft: rgba(201, 100, 66, 0.1);
  --radius: 10px;
  --font-serif: 'Source Serif 4', 'Bitstream Charter', Georgia, serif;
  --font-sans: 'Figtree', 'Fira Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', ui-monospace, monospace;
}

.dark {
  --bg: #141413;
  --surface: #1d1c19;
  --surface-code: #191815;
  --surface-hover: #24231f;
  --fg: #f2f0e8;
  --fg-prose: #dcd9ce;
  --muted: #9a988f;
  --border: #2b2a25;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.14);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  transition: background-color 180ms ease, color 180ms ease;
}

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

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

/* Centered editorial column */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.25rem 1.25rem 6rem;
}

/* Minimal top header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1.25rem;
  margin-bottom: 3.5rem;
  border-bottom: 1px solid var(--border);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
}

.nav-link {
  color: var(--muted);
  padding: 0.25rem 0;
  border-bottom: 1.5px solid transparent;
  transition: color 150ms ease, border-color 150ms ease;
}

.nav-link:hover {
  color: var(--fg);
}

.nav-link.is-active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.theme-toggle:hover {
  color: var(--fg);
  background: var(--surface-hover);
}

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
}

.theme-toggle .icon-sun {
  display: none;
}

.dark .theme-toggle .icon-sun {
  display: block;
}

.dark .theme-toggle .icon-moon {
  display: none;
}

/* Index & Links page headers */
.page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}

.page-kicker {
  margin: 0 0 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.page-heading {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.page-subtitle {
  margin: 0.625rem 0 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--muted);
}

/* Writings list */
.post-list {
  display: flex;
  flex-direction: column;
}

.post-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  padding: 1.125rem 0.75rem;
  margin: 0 -0.75rem;
  border-radius: var(--radius);
  border-bottom: 1px solid var(--border);
  transition: background-color 150ms ease;
}

.post-row:last-child {
  border-bottom: none;
}

.post-row:hover {
  background: var(--surface);
}

.post-info {
  min-width: 0;
}

.post-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  font-weight: 600;
  line-height: 1.38;
  letter-spacing: -0.01em;
  transition: color 150ms ease;
}

.post-row:hover .post-title {
  color: var(--accent);
}

.post-spoiler {
  margin: 0.25rem 0 0;
  font-family: var(--font-serif);
  font-size: 0.96875rem;
  font-style: italic;
  color: var(--muted);
  line-height: 1.45;
}

.post-date {
  flex-shrink: 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Links page */
.links-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.link-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.link-card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.link-card-name {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
}

.link-card-detail {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--muted);
}

.link-card-arrow {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  color: var(--accent);
}

/* Article layout */
.article-header {
  margin-bottom: 2.25rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}

.article-meta {
  display: block;
  margin-bottom: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}

.article-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 2.375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.article-subtitle {
  margin: 0.75rem 0 0;
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  font-style: italic;
  color: var(--muted);
  line-height: 1.45;
}

/* Table of contents */
.toc-box {
  margin-bottom: 2.5rem;
  padding: 1.125rem 1.375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

.toc-heading {
  margin: 0 0 0.625rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
}

.toc-level-3 {
  padding-left: 1rem;
}

.toc-level-4 {
  padding-left: 2rem;
}

.toc-link {
  display: inline-block;
  padding: 0.125rem 0;
  color: var(--fg-prose);
  transition: color 150ms ease;
}

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

/* Article prose */
.prose {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--fg-prose);
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 2.5rem 0 0.875rem;
}

.prose h1 {
  font-size: 2rem;
}

.prose h2 {
  font-size: 1.625rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.prose h3 {
  font-size: 1.3125rem;
  margin-top: 2rem;
}

.prose h4 {
  font-size: 1.125rem;
  margin-top: 1.5rem;
}

.prose p {
  margin: 0 0 1.375rem;
}

.prose a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  transition: color 150ms ease;
}

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

.prose a.anchor {
  text-decoration: none;
}

.prose .inline-code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  padding: 0.125rem 0.375rem;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
}

.prose blockquote {
  margin: 1.75rem 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  border-left: 2.5px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}

.prose blockquote p {
  margin: 0;
}

.prose ul,
.prose ol {
  margin: 0 0 1.375rem;
  padding-left: 1.5rem;
}

.prose li {
  margin-bottom: 0.45rem;
}

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

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

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.prose iframe,
.prose video {
  max-width: 100%;
  margin: 1.5rem 0;
  border-radius: var(--radius);
}

/* Figures */
.figure {
  margin: 2.25rem 0;
}

.figure-frame {
  display: flex;
  justify-content: center;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.figure-frame img {
  display: block;
  max-width: 100%;
  height: auto;
}

.figure-caption {
  margin-top: 0.625rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--muted);
  text-align: center;
}

/* Code blocks + Sugar High warm syntax tokens */
.code-block {
  margin: 1.75rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-code);
  overflow: hidden;
  --sh-keyword: #b54724;
  --sh-string: #2c6e49;
  --sh-comment: var(--muted);
  --sh-function: #2b5b84;
  --sh-number: #9a5b13;
  --sh-identifier: var(--fg);
  --sh-property: #6b4c8c;
  --sh-sign: var(--muted);
  --sh-class: #8a4b2a;
  --sh-jsxliterals: var(--fg);
  --sh-space: var(--fg);
  --sh-break: var(--fg);
}

.dark .code-block {
  --sh-keyword: #e68868;
  --sh-string: #88c096;
  --sh-function: #82b4de;
  --sh-number: #dfb36b;
  --sh-property: #bca0dc;
  --sh-class: #e0a370;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.code-copy {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.code-copy:hover {
  color: var(--fg);
  background: var(--bg);
}

.code-block pre {
  margin: 0;
  padding: 1.125rem 1.25rem;
  overflow-x: auto;
}

.code-block code {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.65;
}

.code-block .sh__token--comment {
  font-style: italic;
}

.code-block.is-folded .code-tail {
  display: none;
}

.code-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.code-toggle {
  width: 100%;
  padding: 0.5rem;
  background: transparent;
  color: var(--muted);
  border: none;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
}

.code-toggle:hover {
  color: var(--fg);
  background: var(--surface-hover);
}

/* Math blocks */
.math-block {
  margin: 1.5rem 0;
  padding: 0.5rem 0;
  overflow-x: auto;
}

/* FadeIn demo */
[data-fade-in] {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1s ease-in-out, transform 1s ease-in-out;
}

[data-fade-in].is-visible {
  opacity: 1;
  transform: translateY(0);
}

.fade-finale {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.25rem;
  margin: 4rem 0;
}

/* Subtle editorial end mark */
.end-mark {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  letter-spacing: 0.4em;
  user-select: none;
}

@media (max-width: 600px) {
  .container {
    padding: 1.5rem 1rem 4rem;
  }

  .site-header {
    margin-bottom: 2.5rem;
  }

  .post-row {
    flex-direction: column;
    gap: 0.35rem;
  }

  .article-title {
    font-size: 1.875rem;
  }

  .prose {
    font-size: 1.0625rem;
  }
}

@media (min-width: 768px) {
  .container {
    padding-top: 3.5rem;
  }

  .page-heading {
    font-size: 2.625rem;
  }

  .article-title {
    font-size: 2.75rem;
  }

  .prose {
    font-size: 1.1875rem;
  }
}
