:root {
  color-scheme: light;
  --ink: #241c17;
  --muted: #75685f;
  --paper: #fffaf2;
  --paper-strong: #fff5e6;
  --line: rgba(73, 51, 35, 0.18);
  --accent: #9d3b34;
  --accent-dark: #70251f;
  --shadow: 0 22px 70px rgba(80, 51, 25, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
  scrollbar-width: none;
  background:
    radial-gradient(circle at 18% 8%, rgba(157, 59, 52, 0.12), transparent 28rem),
    linear-gradient(135deg, #f8efe2 0%, #f3e5d2 48%, #efe4dc 100%);
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  -ms-overflow-style: none;
  color: var(--ink);
  font-family:
    "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
}

.page-shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(34px, 6vw, 64px) 0 132px;
}

.letter-header {
  margin-bottom: 28px;
}

.kicker {
  margin: 0 0 14px;
  color: var(--accent);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.letter-header h1 {
  margin: 0;
  font-size: clamp(2.05rem, 8vw, 4.8rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: 0;
}

.subtitle {
  max-width: 680px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.6vw, 1.2rem);
  line-height: 1.8;
}

.letter-card {
  position: relative;
  padding: clamp(22px, 6vw, 64px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(157, 59, 52, 0.04) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(var(--paper), var(--paper-strong));
  box-shadow: var(--shadow);
}

.letter-card::before {
  position: absolute;
  inset: 18px;
  pointer-events: none;
  border: 1px solid rgba(157, 59, 52, 0.13);
  border-radius: 6px;
  content: "";
}

.letter-card > * {
  position: relative;
}

.letter-card h1,
.letter-card h2,
.letter-card h3 {
  scroll-margin-top: 32px;
  margin: 2em 0 0.75em;
  line-height: 1.35;
}

.letter-card h1 {
  font-size: clamp(1.45rem, 4.8vw, 2rem);
}

.letter-card h2 {
  font-size: clamp(1.26rem, 4vw, 1.58rem);
}

.letter-card h3 {
  font-size: clamp(1.12rem, 3.4vw, 1.34rem);
}

.letter-card h1:first-child,
.letter-card h2:first-child,
.letter-card h3:first-child {
  margin-top: 0;
}

.letter-card p,
.letter-card li,
.letter-card blockquote {
  font-size: clamp(1.06rem, 2.7vw, 1.22rem);
  line-height: 2.05;
}

.letter-card p {
  margin: 0 0 1.25em;
}

.letter-card blockquote {
  margin: 1.8em 0;
  padding: 0.15em 0 0.15em 1.2em;
  border-left: 3px solid var(--accent);
  color: #49382f;
}

.letter-card a {
  color: var(--accent-dark);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}

.loading {
  color: var(--muted);
}

.toc {
  position: sticky;
  top: 0;
  z-index: 4;
  width: min(100% - 24px, 920px);
  margin: 0 auto;
  padding: 10px 0 0;
  background: rgba(248, 239, 226, 0.94);
  backdrop-filter: blur(12px);
  font-family: "Segoe UI", Arial, sans-serif;
}

.toc:empty {
  display: none;
}

.toc-title {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.toc-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 10px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}

.toc-list::-webkit-scrollbar {
  display: none;
}

.toc-link {
  flex: 0 0 auto;
  max-width: min(220px, 56vw);
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid rgba(73, 51, 35, 0.16);
  border-radius: 6px;
  background: rgba(255, 250, 242, 0.72);
  color: var(--accent-dark);
  font-size: 0.9rem;
  line-height: 1.35;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-link:hover,
.toc-link:focus-visible {
  border-color: rgba(157, 59, 52, 0.45);
  background: rgba(255, 250, 242, 0.96);
}

.toc-link.is-active {
  color: var(--accent);
  font-weight: 800;
}

.toc-level-2 {
  opacity: 0.9;
}

.toc-level-3 {
  opacity: 0.78;
}

@media (min-width: 1180px) {
  html {
    scroll-padding-top: 32px;
  }

  .page-shell {
    width: min(820px, calc(100vw - 520px));
    margin-left: auto;
    margin-right: auto;
  }

  .toc {
    position: fixed;
    top: 62px;
    left: 24px;
    z-index: 3;
    width: 210px;
    max-height: calc(100vh - 96px);
    margin: 0;
    padding: 0;
    color: var(--muted);
  }

  .toc-list {
    display: grid;
    gap: 2px;
    overflow-y: auto;
    max-height: calc(100vh - 130px);
    padding: 0 10px 0 0;
    border-left: 1px solid rgba(73, 51, 35, 0.2);
    mask-image: linear-gradient(180deg, #000 0, #000 calc(100% - 24px), transparent 100%);
  }

  .toc-link {
    width: 100%;
    max-width: none;
    padding: 7px 0 7px 14px;
    border: 0;
    border-left: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: normal;
  }

  .toc-link:hover,
  .toc-link:focus-visible {
    border-color: var(--accent);
    background: transparent;
    color: var(--accent-dark);
  }

  .toc-link.is-active {
    border-left-color: var(--accent);
    color: var(--accent-dark);
    font-weight: 800;
  }

  .toc-level-2 {
    padding-left: 26px;
  }

  .toc-level-3 {
    padding-left: 38px;
  }
}

@media (min-width: 1480px) {
  .toc {
    left: max(42px, calc((100vw - 1420px) / 2));
    width: 230px;
  }
}

@media (max-width: 640px) {
  html {
    scroll-padding-top: 84px;
  }

  .toc {
    width: 100%;
    padding: 8px 12px 0;
  }

  .toc-title {
    margin-bottom: 8px;
  }

  .page-shell {
    width: min(100% - 20px, 920px);
    padding-top: 24px;
  }

  .kicker {
    font-size: 0.72rem;
  }

  .subtitle {
    margin-top: 14px;
    line-height: 1.7;
  }

  .letter-card {
    border-radius: 6px;
    box-shadow: 0 16px 44px rgba(80, 51, 25, 0.13);
  }

  .letter-card::before {
    inset: 10px;
  }

  .letter-card h1,
  .letter-card h2,
  .letter-card h3 {
    scroll-margin-top: 92px;
  }
}

@media (max-width: 360px) {
  .page-shell {
    width: min(100% - 16px, 920px);
  }

  .letter-card {
    padding: 20px;
  }

  .letter-card::before {
    inset: 8px;
  }

  .letter-card p,
  .letter-card li,
  .letter-card blockquote {
    font-size: 1rem;
    line-height: 1.95;
  }
}
