/* ==========================================================================
   Tufte-inspired Minimalist Editorial Stylesheet
   Zero external assets · Pure CSS · Light & Dark archival palettes
   ========================================================================== */

:root {
  --bg: #fffff8;
  --fg: #111111;
  --muted: #6c675e;
  --rule: #e6e2d8;
  --code-bg: #f6f4ec;
  --link-line: #b8b2a6;

  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
    Georgia, "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", "STSong",
    serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono",
    monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --fg: #e7e4dc;
    --muted: #9a958b;
    --rule: #2a2925;
    --code-bg: #1e1e1b;
    --link-line: #56524a;
  }
}

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

html {
  font-size: 16px;
  background-color: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.75;
  counter-reset: sidenote-counter;
}

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

/* ---------- Page Container ---------- */

.page {
  max-width: 1020px;
  margin: 0 auto;
  padding: 2.5rem 2.25rem 5rem;
}

/* ---------- Top Minimalist Navigation ---------- */

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1.15rem;
  margin-bottom: 3.5rem;
  border-bottom: 1px solid var(--rule);
}

.site-brand {
  font-size: 1.05rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--fg);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: baseline;
  gap: 1.85rem;
  font-size: 0.96rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  padding-bottom: 0.15rem;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

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

.site-nav a[aria-current="page"] {
  color: var(--fg);
  border-bottom-color: var(--fg);
}

/* ---------- Main Article & Column Geometry ---------- */

main {
  display: block;
}

article {
  position: relative;
}

article::after {
  content: "";
  display: table;
  clear: both;
}

/* Desktop two-zone Tufte geometry: 58% reading column + right margin */
article > h1,
article > h2,
article > h3,
article > p,
article > ul,
article > ol,
article > blockquote,
article > pre,
article > .subtitle,
article > .section-label,
article > .entry-list,
article > .project-list,
article > .post-back {
  width: 58%;
}

/* ---------- Typography ---------- */

h1 {
  font-weight: 400;
  font-size: 2.3rem;
  line-height: 1.18;
  letter-spacing: -0.01em;
  margin: 0 0 0.65rem;
}

.subtitle {
  margin: 0 0 2.4rem;
  font-style: italic;
  font-size: 1.15rem;
  line-height: 1.55;
  color: var(--muted);
}

h2 {
  font-weight: 400;
  font-style: italic;
  font-size: 1.45rem;
  line-height: 1.3;
  margin: 2.6rem 0 0.9rem;
}

h3 {
  font-weight: 400;
  font-size: 1.15rem;
  line-height: 1.4;
  margin: 1.8rem 0 0.6rem;
}

p {
  margin: 0 0 1.35rem;
}

ul,
ol {
  margin: 0 0 1.4rem;
  padding-left: 1.35rem;
}

li {
  margin-bottom: 0.45rem;
}

.newthought {
  font-variant: small-caps;
  letter-spacing: 0.04em;
  font-size: 1.05em;
}

/* ---------- Links ---------- */

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}

a:hover {
  text-decoration-color: var(--fg);
}

/* ---------- Epigraphs & Blockquotes ---------- */

blockquote {
  margin: 1.8rem 0 2.1rem;
  padding-left: 1.25rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

blockquote p {
  font-style: italic;
  margin-bottom: 0.45rem;
}

blockquote footer {
  font-size: 0.88rem;
  font-style: normal;
  text-align: right;
  color: var(--muted);
}

/* ---------- Code ---------- */

code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background-color: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 2px;
}

pre {
  margin: 1.5rem 0 1.75rem;
  padding: 1rem 1.2rem;
  background-color: var(--code-bg);
  border-left: 2px solid var(--rule);
  overflow-x: auto;
  line-height: 1.55;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.84rem;
}

/* ---------- Sidenotes & Marginnotes (Pure CSS) ---------- */

input.margin-toggle {
  display: none;
}

label.margin-toggle {
  display: inline;
}

label.margin-toggle:not(.sidenote-number) {
  display: none;
}

.sidenote-number {
  counter-increment: sidenote-counter;
}

.sidenote-number::after,
.sidenote::before {
  font-family: var(--font-serif);
  font-size: 0.72rem;
  position: relative;
  vertical-align: baseline;
}

.sidenote-number::after {
  content: counter(sidenote-counter);
  top: -0.45rem;
  left: 0.1rem;
  padding-right: 0.15rem;
  color: var(--muted);
}

.sidenote::before {
  content: counter(sidenote-counter) ". ";
  color: var(--muted);
}

.sidenote,
.marginnote {
  float: right;
  clear: right;
  margin-right: -66%;
  width: 56%;
  margin-top: 0.25rem;
  margin-bottom: 0.85rem;
  font-size: 0.86rem;
  line-height: 1.58;
  color: var(--muted);
  vertical-align: baseline;
  position: relative;
}

/* ---------- Section Headings & Editorial Lists ---------- */

.section-label {
  margin: 2.8rem 0 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.entry-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
  border-top: 1px solid var(--rule);
}

.entry-item {
  display: grid;
  grid-template-columns: 7.25rem 1fr;
  gap: 1rem;
  align-items: baseline;
  padding: 0.78rem 0;
  margin: 0;
  border-bottom: 1px solid var(--rule);
}

.entry-date {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.entry-title {
  font-size: 1.04rem;
}

.entry-title.is-muted {
  color: var(--muted);
}

.entry-tag {
  margin-left: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.more-link {
  font-size: 0.92rem;
  color: var(--muted);
}

/* ---------- Projects List ---------- */

.project-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--rule);
}

.project-item {
  padding: 1.15rem 0;
  margin: 0;
  border-bottom: 1px solid var(--rule);
}

.project-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.project-name {
  font-size: 1.08rem;
  font-weight: 400;
}

.project-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.project-desc {
  margin: 0;
  font-size: 0.98rem;
  color: var(--muted);
}

/* ---------- Post Back-link & Site Footer ---------- */

.post-back {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
  color: var(--muted);
}

.site-footer {
  margin-top: 4.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--muted);
}

/* ---------- Responsive: Single Column on Narrow Viewports ---------- */

@media (max-width: 860px) {
  .page {
    padding: 1.65rem 1.25rem 3.5rem;
  }

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

  .site-nav {
    gap: 1.25rem;
  }

  article > h1,
  article > h2,
  article > h3,
  article > p,
  article > ul,
  article > ol,
  article > blockquote,
  article > pre,
  article > .subtitle,
  article > .section-label,
  article > .entry-list,
  article > .project-list,
  article > .post-back {
    width: 100%;
  }

  h1 {
    font-size: 1.9rem;
  }

  label.margin-toggle {
    cursor: pointer;
  }

  label.margin-toggle:not(.sidenote-number) {
    display: inline;
    margin-left: 0.15rem;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--muted);
    vertical-align: super;
  }

  .sidenote,
  .marginnote {
    display: none;
  }

  .margin-toggle:checked + .sidenote,
  .margin-toggle:checked + .marginnote {
    display: block;
    float: left;
    left: 0;
    clear: both;
    width: 94%;
    margin: 0.75rem 0 0.9rem 3%;
    padding-left: 0.85rem;
    border-left: 2px solid var(--rule);
  }

  .entry-item {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}
