:root {
  --bg: #f2f0e8;
  --bg-top: #f6f4ec;
  --glow: rgba(193, 176, 142, 0.15);
  --text: #171717;
  --muted: #626262;
  --rule: #d9d0c0;
  --link: #111;
  --link-hover: #3f3f3f;
  --body-copy: #121212;
  --heading-copy: #0e0e0e;
  --button-bg: rgba(255, 255, 255, 0.58);
  --button-border: #cfc5b4;
  --button-border-strong: #b8ae9d;
  --button-text: #353535;
  --toc-rail: #ddd5c7;
  --toc-active-rail: #baad96;
  --toc-active-rail-sub: #cbc1af;
  --code-inline-bg: rgba(217, 208, 192, 0.3);
  --code-block-bg: rgba(217, 208, 192, 0.24);
  --grain-opacity: 0.028;
  --max-home: calc(var(--content) + 3rem);
  --max-essay: 78rem;
  --content: 46rem;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}

[data-theme="dark"] {
  --bg: #151515;
  --bg-top: #1c1c1c;
  --glow: rgba(144, 116, 82, 0.15);
  --text: #e9e7e1;
  --muted: #b2aca0;
  --rule: #413b31;
  --link: #f0ede3;
  --link-hover: #d8cfbd;
  --body-copy: #ece8de;
  --heading-copy: #f5f2ea;
  --button-bg: rgba(40, 40, 40, 0.62);
  --button-border: #5a5347;
  --button-border-strong: #4a443a;
  --button-text: #e9e3d6;
  --toc-rail: #4a4338;
  --toc-active-rail: #8b8275;
  --toc-active-rail-sub: #6f675c;
  --code-inline-bg: rgba(65, 59, 49, 0.44);
  --code-block-bg: rgba(65, 59, 49, 0.36);
  --grain-opacity: 0.02;
}

* {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  transition:
    color 220ms cubic-bezier(0.22, 0.9, 0.3, 1),
    border-color 300ms ease,
    text-decoration-color 220ms cubic-bezier(0.22, 0.9, 0.3, 1);
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background-color: var(--bg);
  transition: background-color 220ms linear;
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  background: transparent;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
  transition: opacity 220ms linear;
}

body::before {
  opacity: 1;
  background:
    radial-gradient(1400px 700px at 10% -15%, rgba(193, 176, 142, 0.09), transparent 50%),
    linear-gradient(180deg, #f4f2ea 0%, #f2f0e8 22rem, #f2f0e8 100%);
}

body::after {
  opacity: 0;
  background:
    radial-gradient(1400px 700px at 10% -15%, rgba(144, 116, 82, 0.09), transparent 50%),
    linear-gradient(180deg, #1c1c1c 0%, #151515 22rem, #151515 100%);
}

[data-theme="dark"] body::before {
  opacity: 0;
}

[data-theme="dark"] body::after {
  opacity: 1;
}

.grain {
  display: none;
}

.page-home {
  font-size: 22px;
  padding-bottom: 10vh;
}

.home-shell {
  max-width: var(--max-essay);
  margin: 0 auto;
  min-height: 100vh;
  padding: 2.35rem 1.5rem 4rem;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 2.55rem;
}

.home-header,
.essay-header {
  position: relative;
}

.home-header {
  width: min(100%, var(--content));
  margin: 0 auto;
  padding-top: 0.2rem;
}

.theme-toggle {
  --switch-w: 2.92rem;
  --switch-h: 1.56rem;
  --switch-gap: 0.16rem;
  --switch-thumb: 0.96rem;
  position: absolute;
  top: 0;
  right: 0;
  border: 2px solid var(--button-border-strong);
  background: var(--button-bg);
  color: transparent;
  width: var(--switch-w);
  height: var(--switch-h);
  padding: 0;
  border-radius: calc(var(--switch-h) / 2);
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition:
    background-color 300ms ease,
    border-color 300ms ease;
}

.theme-toggle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: var(--switch-gap);
  width: var(--switch-thumb);
  height: var(--switch-thumb);
  border-radius: 50%;
  background: var(--button-text);
  transform: translateY(-50%);
  transition:
    left 300ms cubic-bezier(0.22, 0.9, 0.3, 1),
    background-color 300ms ease;
}

[data-theme="dark"] .theme-toggle::before {
  left: calc(100% - var(--switch-gap) - var(--switch-thumb));
  transform: translateY(-50%);
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  border-color: var(--text);
}

.home-header p {
  margin: 0.7rem 0 0;
  max-width: 38rem;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 1.04rem;
  line-height: 1.45;
  font-style: italic;
}

#category-root {
  width: min(100%, var(--content));
  margin: 0 auto;
  display: grid;
  gap: 2.05rem;
}

.home-section {
  border-top: 1px solid var(--rule);
  padding-top: 1.1rem;
}

.home-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.95rem;
}

.home-section h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.22rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
}

.home-count {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.essay-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.home-entry {
  display: grid;
  gap: 0.36rem;
  padding: 0.92rem 0;
  border-top: 1px solid var(--rule);
}

.essay-list li:last-child {
  border-bottom: 1px solid var(--rule);
}

.home-entry-title {
  font-size: 1.2rem;
  text-decoration: none;
}

.home-entry-title:hover,
.home-entry-title:focus-visible {
  text-decoration: underline;
}

.home-entry-dek {
  margin: 0;
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.45;
}

.home-entry-date {
  font-size: 0.78rem;
}

a {
  color: var(--link);
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.18em;
}

a:hover,
a:focus-visible {
  color: var(--link-hover);
}

time,
.meta {
  font-family: var(--serif);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.home-footer {
  width: min(100%, var(--content));
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}

.home-footer a {
  text-decoration: none;
  color: var(--muted);
}

.home-footer a:hover,
.home-footer a:focus-visible {
  color: var(--text);
  text-decoration: underline;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  color: var(--muted);
  text-decoration: none;
}

.icon-link svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.icon-link.icon-x svg {
  width: 88%;
  height: 88%;
}

.icon-link:hover,
.icon-link:focus-visible {
  color: var(--text);
  text-decoration: none;
}

.empty-state {
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.95rem;
}

.page-essay {
  font-size: 22px;
}

.essay-shell {
  max-width: var(--max-essay);
  margin: 0 auto;
  padding: 2.35rem 1.5rem 4rem;
}

.essay-header {
  max-width: var(--content);
  margin: 0 auto 2.8rem;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}

.home-link {
  font-family: var(--serif);
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--muted);
}

.essay-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0;
  min-height: 2rem;
}

.essay-meta-row .home-link {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.essay-meta-row .theme-toggle {
  position: relative;
  --switch-w: 3.08rem;
  --switch-h: 1.62rem;
  --switch-gap: 0.17rem;
  --switch-thumb: 0.98rem;
}

.home-link:hover,
.home-link:focus-visible {
  color: var(--text);
  text-decoration: underline;
}

.essay-header h1 {
  margin: 2.35rem 0 0.8rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-size: clamp(2rem, 4.8vw, 3.35rem);
}

.dek {
  margin: 0;
  color: var(--body-copy);
  font-style: italic;
}

.essay-layout {
  position: relative;
}

.toc {
  position: fixed;
  top: 1.45rem;
  left: 1.25rem;
  width: 17.25rem;
  padding-top: 0;
  z-index: 10;
}

.toc-panel h2 {
  margin: -0.18rem 0 0.48rem;
  font-family: var(--serif);
  font-size: 1.38rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--muted);
}

.toc-toggle:hover,
.toc-toggle:focus-visible {
  color: var(--text);
}

.toc-toggle {
  position: relative;
  width: 2.35rem;
  height: 2.05rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  margin: 0 0 0.45rem;
}

.toc-toggle-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.72rem;
  height: 0.72rem;
  border-top: 2.6px solid currentColor;
  border-right: 2.6px solid currentColor;
  border-radius: 1px;
  transform: translate(-50%, -50%) rotate(45deg);
  transition: transform 220ms cubic-bezier(0.22, 0.9, 0.3, 1);
}

.toc-toggle[aria-expanded="true"] .toc-toggle-icon {
  transform: translate(-50%, -50%) rotate(135deg);
}

.toc-panel {
  --toc-fade-size: 2rem;
  position: relative;
  margin-top: 6rem;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-0.2rem);
  transition: max-height 210ms ease, opacity 180ms ease, transform 210ms ease;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior-y: contain;
  overscroll-behavior-x: contain;
}

.toc.open .toc-panel {
  max-height: 56vh;
  opacity: 1;
  overflow: hidden;
  transform: translateY(0);
}

.toc.open.scroll-ready .toc-panel {
  overflow: auto;
}

.toc-panel::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.toc.open.scroll-ready.toc-can-scroll .toc-panel {
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 var(--toc-fade-size),
    #000 calc(100% - var(--toc-fade-size)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 var(--toc-fade-size),
    #000 calc(100% - var(--toc-fade-size)),
    transparent 100%
  );
}

.toc.open.scroll-ready.toc-can-scroll.toc-at-top .toc-panel {
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - var(--toc-fade-size)), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - var(--toc-fade-size)), transparent 100%);
}

.toc.open.scroll-ready.toc-can-scroll.toc-at-bottom .toc-panel {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--toc-fade-size), #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 var(--toc-fade-size), #000 100%);
}

.toc.open.scroll-ready.toc-can-scroll.toc-at-top.toc-at-bottom .toc-panel {
  -webkit-mask-image: none;
  mask-image: none;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--toc-rail);
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  padding: 0.56rem 0 0.56rem 0.95rem;
  font-family: var(--serif);
  font-size: 1.12rem;
  color: var(--muted);
  text-decoration: none;
  transition: color 160ms ease, border-color 160ms ease;
  border-left: 3px solid transparent;
  margin-left: -1px;
}

.toc a:hover,
.toc a:focus-visible {
  color: var(--text);
}

.toc a.active {
  color: var(--text);
  border-left-color: var(--toc-active-rail);
}

.essay-content {
  max-width: var(--content);
  margin: 0 auto;
  font-size: 0.95em;
}

.essay-content p {
  color: var(--body-copy);
  font-weight: 400;
  line-height: 1.54;
  margin: 0 0 1.2rem;
}

.essay-content h1,
.essay-content h2 {
  font-family: var(--serif);
  color: var(--heading-copy);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.28;
}

.essay-content h3,
.essay-content h4 {
  font-family: var(--serif);
  color: var(--heading-copy);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.28;
}

.essay-content h1 {
  margin: 0.2rem 0 1rem;
  font-size: 1.78rem;
}

.essay-content ul,
.essay-content ol {
  margin: 0 0 1.2rem 1.25rem;
  color: var(--body-copy);
}

.essay-content li {
  margin: 0.2rem 0;
}

.essay-content blockquote {
  margin: 0 0 1.2rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

.essay-content hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 1.6rem 0 1.55rem;
}

.essay-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88em;
  background: var(--code-inline-bg);
  padding: 0.08em 0.3em;
  border-radius: 4px;
}

.essay-content pre {
  margin: 0 0 1.2rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--code-block-bg);
  overflow-x: auto;
}

.essay-content pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 0.85em;
  line-height: 1.55;
}

.essay-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.3rem;
  font-size: 0.92em;
}

.essay-content th,
.essay-content td {
  text-align: left;
  padding: 0.46rem 0.55rem;
  border-bottom: 1px solid var(--rule);
}

.essay-content th {
  font-weight: 600;
  color: var(--heading-copy);
}

.chapter {
  margin: 2.65rem 0 0;
  scroll-margin-top: 1rem;
}

.chapter h2 {
  font-family: var(--serif);
  font-size: 1.52rem;
  letter-spacing: -0.005em;
  font-weight: 600;
  color: var(--heading-copy);
  margin: 0 0 0.9rem;
}

.essay-content h3 {
  margin: 1.8rem 0 0.8rem;
  font-size: 1.28rem;
}

.essay-content h4 {
  margin: 1.4rem 0 0.7rem;
  font-size: 1.12rem;
}

.toc-sub {
  list-style: none;
  margin: 0.3rem 0 0.62rem 0.82rem;
  padding: 0;
  display: none;
  border-left: 1px solid var(--toc-rail);
}

.toc-sub-item {
  margin: 0;
}

.toc li.toc-current .toc-sub {
  display: block;
}

.toc-sub .toc-sub {
  margin-left: 0.65rem;
}

.toc li.toc-current > .toc-sub,
.toc li.toc-current > .toc-sub .toc-sub {
  border-left-color: var(--toc-active-rail-sub);
  border-left-width: 2px;
}

.toc-sub-item a {
  font-size: 1.03rem;
  padding-top: 0.38rem;
  padding-bottom: 0.38rem;
}

.toc-sub-item.level-4 a {
  padding-left: 0.5rem;
}

.toc-sub-item.level-5 a,
.toc-sub-item.level-6 a {
  padding-left: 0.9rem;
}

@media (max-width: 1000px) {
  .page-home,
  .page-essay {
    font-size: 20px;
  }

  .essay-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .toc {
    position: sticky;
    top: 0.85rem;
    width: auto;
    left: auto;
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    padding: 1rem 0;
  }

  .toc-list {
    border-left: 0;
    display: grid;
    gap: 0.25rem;
  }

  .toc-sub {
    border-left: 0;
    margin-left: 0.35rem;
  }

  .toc a {
    border-left: 0;
    margin-left: 0;
    padding-left: 0;
  }

  .toc a.active {
    text-decoration: underline;
    text-underline-offset: 0.18em;
  }
}

@media (max-width: 640px) {
  .home-shell {
    padding-top: 3rem;
    gap: 2.4rem;
  }

  .essay-shell {
    padding-top: 3rem;
  }

  .home-header .theme-toggle {
    position: relative;
  }
}
