:root {
  --bg: #fdfdfc;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e5e3df;
  --accent: #8a1c1c;
  --chip-bg: transparent;
  --chip-fg: #4a4a4a;
  --chip-border: #d6d3cd;
  --serif: "Source Serif 4", "Source Serif Pro", "Noto Serif SC", "Songti SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Helvetica Neue", sans-serif;
  --max: 880px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --fg: #e8e6e1;
    --muted: #9a9690;
    --line: #2c2a27;
    --accent: #d97a7a;
    --chip-fg: #c0bcb4;
    --chip-border: #3a3733;
  }
}

* { box-sizing: border-box; }

html { font-size: 17px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  line-height: 1.7;
  font-feature-settings: "kern", "liga";
  text-rendering: optimizeLegibility;
}

.container {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.25rem;
}

a {
  color: var(--fg);
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  padding: 1.1rem 0;
  margin-bottom: 2.5rem;
}
.site-header .container {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--accent);
}
.brand:hover { color: var(--accent); }
.nav {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: flex;
  gap: 1.1rem;
}
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--accent); }

/* Footer */
.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 4rem;
  padding: 1.5rem 0;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--muted);
}
.site-footer .container { display: flex; justify-content: space-between; }

/* Headings */
.page-title {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 1.5rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.6rem;
}
.page-sub {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: 0.6rem;
  font-weight: 400;
}

/* Timeline / cards */
.timeline-month {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2rem 0 0.8rem;
}
.card {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}
.card:last-child { border-bottom: none; }
.card-title {
  font-size: 1.08rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  line-height: 1.4;
}
.card-title a { text-decoration: none; }
.card-summary {
  margin: 0.2rem 0 0.4rem;
  color: var(--fg);
  font-size: 0.98rem;
  line-height: 1.6;
}
.card-date {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
}

/* Article */
.article-header { margin: 1.5rem 0 1.8rem; }
.article-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 0.6rem;
}
.lede {
  font-size: 1.08rem;
  color: var(--muted);
  font-style: italic;
  margin: 0;
  line-height: 1.6;
}
.article-body {
  font-size: 1.04rem;
  text-align: justify;
  text-justify: inter-ideograph;
  hyphens: auto;
}
.article-body p { margin: 0 0 1.1rem; }
.article-body h2 { font-size: 1.3rem; margin: 2rem 0 0.8rem; }
.article-body h3 { font-size: 1.1rem; margin: 1.6rem 0 0.6rem; }
.article-body blockquote {
  border-left: 3px solid var(--line);
  padding: 0 0 0 1rem;
  margin: 1rem 0;
  color: var(--muted);
}
.article-body img { max-width: 100%; height: auto; }

/* Article meta (footer of single article) */
.article-meta {
  margin-top: 2.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
}
.article-meta dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}
.article-meta dt { color: var(--muted); }
.article-meta dd { margin: 0; color: var(--fg); }
.article-meta dd a { color: var(--fg); }

/* Chips */
.chip {
  display: inline;
  font-size: inherit;
  padding: 0;
  margin: 0 0.7rem 0 0;
  border: 0;
  border-radius: 0;
  color: var(--fg);
  text-decoration: none;
  background: transparent;
}
.chip:hover { color: var(--accent); }
.chip-series { border-style: none; }

/* Series box on article */
.series-box {
  margin: 2rem 0;
  padding: 0.9rem 1rem;
  border: 1px dashed var(--line);
  background: transparent;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.series-box h3 { margin: 0 0 0.4rem; font-size: 0.95rem; font-weight: 500; }
.series-box p { margin: 0; color: var(--muted); }

/* Series term page */
.section-h {
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2rem 0 0.8rem;
}
.series-timeline { list-style: none; padding: 0; margin: 0; }
.series-timeline li {
  border-left: 2px solid var(--line);
  padding: 0.4rem 0 0.8rem 1rem;
  margin-left: 0.4rem;
  position: relative;
}
.series-timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 0.8rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.series-timeline time {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}
.series-timeline a { font-weight: 600; }
.series-timeline p { margin: 0.2rem 0 0; font-size: 0.92rem; color: var(--muted); }
.series-summary { font-size: 0.98rem; }

/* Term list (categories / labels listing) */
.term-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  font-family: var(--sans);
  font-size: 0.95rem;
}
.term-list li a {
  text-decoration: none;
  color: var(--fg);
  border-bottom: 1px solid transparent;
  padding: 0.05rem 0;
}
.term-list li a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* Archive */
.archive-year {
  font-size: 1.4rem;
  margin: 2rem 0 0.6rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.3rem;
}
.archive-month {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin: 1rem 0 0.4rem;
  letter-spacing: 0.05em;
}
.archive-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.archive-list li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.3rem 0;
  line-height: 1.5;
  font-size: 0.98rem;
}
.archive-list time {
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--muted);
  width: 3.2em;
  flex-shrink: 0;
}
.archive-list a { text-decoration: none; }
.archive-list a:hover { color: var(--accent); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 2.5rem 0;
  font-family: var(--sans);
  font-size: 0.85rem;
  list-style: none;
  padding: 0;
}
.pagination a, .pagination .active {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  text-decoration: none;
  color: var(--muted);
}
.pagination .active { color: var(--accent); border-color: var(--accent); }

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

/* Heatmap */
:root {
  --hm-cell: 12px;
  --hm-gap: 2px;
  --hm-l0: #ebedf0;
  --hm-l1: #c6e7c1;
  --hm-l2: #7ac57a;
  --hm-l3: #399f50;
  --hm-l4: #1d6b33;
}
@media (prefers-color-scheme: dark) {
  :root {
    --hm-l0: #2a2926;
    --hm-l1: #2d4a36;
    --hm-l2: #3f7c4f;
    --hm-l3: #5fb16c;
    --hm-l4: #8ed68f;
  }
}
.heatmap {
  margin: 0 auto 2rem;
  padding: 1rem 1rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--muted);
  width: max-content;
  max-width: 100%;
}
.heatmap-scroll { overflow-x: auto; }
.heatmap-months {
  display: grid;
  grid-template-columns: repeat(53, calc(var(--hm-cell) + var(--hm-gap)));
  padding-left: calc(var(--hm-cell) + 14px);
  margin-bottom: 4px;
}
.hm-month { font-size: 0.72rem; color: var(--muted); }
.heatmap-body {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.heatmap-weekdays {
  display: grid;
  grid-template-rows: repeat(7, var(--hm-cell));
  gap: var(--hm-gap);
  font-size: 0.7rem;
  color: var(--muted);
}
.heatmap-weekdays span { display: flex; align-items: center; height: var(--hm-cell); }
.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, var(--hm-cell));
  grid-auto-flow: column;
  grid-auto-columns: var(--hm-cell);
  gap: var(--hm-gap);
}
.hm-cell {
  width: var(--hm-cell);
  height: var(--hm-cell);
  border-radius: 2px;
  display: block;
  background: var(--hm-l0);
  text-decoration: none;
  outline: 1px solid transparent;
  transition: outline-color .1s;
}
.hm-cell:hover { outline-color: var(--accent); }
.hm-l0 { background: var(--hm-l0); }
.hm-l1 { background: var(--hm-l1); }
.hm-l2 { background: var(--hm-l2); }
.hm-l3 { background: var(--hm-l3); }
.hm-l4 { background: var(--hm-l4); }
.hm-future { background: transparent; }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 8px;
  font-size: 0.72rem;
}
.heatmap-legend .hm-cell { cursor: default; }

/* day anchor offset */
.archive-list li[id] { scroll-margin-top: 5rem; }
.archive-list li[id] { background: linear-gradient(transparent 60%, transparent 60%); }
.archive-list li[id]:target {
  background: rgba(217, 122, 122, 0.12);
  border-radius: 4px;
  margin-left: -8px;
  padding-left: 8px;
  margin-right: -8px;
  padding-right: 8px;
}

/* Floating TOC */
.article-wrap { position: relative; }
.toc {
  position: fixed;
  top: 5.5rem;
  left: max(1rem, calc(50% - 640px));
  width: 180px;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--muted);
  padding-right: 0.6rem;
  border-right: 1px solid var(--line);
}
.toc-label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
  font-weight: 500;
}
.toc nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc nav ul ul {
  padding-left: 0.8rem;
  margin: 0.2rem 0;
}
.toc nav li { margin: 0.25rem 0; }
.toc nav a {
  color: var(--muted);
  text-decoration: none;
  display: block;
  padding: 0.05rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  margin-left: -0.5rem;
  transition: color .15s, border-color .15s;
}
.toc nav a:hover { color: var(--accent); border-left-color: var(--accent); }
.toc::-webkit-scrollbar { width: 6px; }
.toc::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

@media (max-width: 1260px) {
  .toc { display: none; }
}

/* Anchor heading offset (so jump targets aren't hidden behind sticky header) */
.article-body h2, .article-body h3 { scroll-margin-top: 5rem; }
