@font-face {
  font-family: "YF Serif";
  src: url("/assets/fonts/source-han-serif-sc-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond";
  src: url("/assets/fonts/eb-garamond-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond";
  src: url("/assets/fonts/eb-garamond-italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "YF Hand";
  src: url("/assets/fonts/lxgw-wenkai-signature.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "YF Mono";
  src: url("/assets/fonts/maple-mono-cn-dateline.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "YF Sans";
  src: url("/assets/fonts/source-han-sans-sc-ui-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "YF Sans";
  src: url("/assets/fonts/source-han-sans-sc-ui-medium.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Radix sand, light */
  --sand-1: #fdfdfc;
  --sand-2: #f9f9f8;
  --sand-3: #f1f0ef;
  --sand-4: #e9e8e6;
  --sand-5: #e2e1de;
  --sand-6: #dad9d6;
  --sand-7: #cfceca;
  --sand-8: #bcbbb5;
  --sand-9: #8d8d86;
  --sand-10: #82827c;
  --sand-11: #63635e;
  --sand-12: #21201c;

  /* Radix sage, light */
  --sage-5: #dfe2e0;
  --sage-9: #868e8b;
  --sage-11: #5f6563;

  --paper: var(--sand-1);
  --ink: var(--sand-12);
  --ink-secondary: var(--sand-11);
  --rule: var(--sand-6);
  --rule-strong: var(--sand-7);
  --accent: var(--sage-11);
  --focus: var(--sage-9);

  --hairline: 0.5px;
  --measure: 36rem;
  --pad: clamp(20px, 4vw, 48px);

  --font-body: "YF Serif", "Source Han Serif SC", "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  --font-display: "EB Garamond", "YF Serif", "Songti SC", "Noto Serif CJK SC", Georgia, serif;
  --font-ui: "YF Sans", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-hand: "YF Hand", "LXGW WenKai", "Kaiti SC", "KaiTi", serif;
  --font-mono: "YF Mono", ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
}

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

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.9;
}

h1,
h2,
p,
ol,
figure {
  margin: 0;
  padding: 0;
}

ol {
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
}

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

::selection {
  background: var(--sage-5);
  color: var(--sand-12);
}

:focus-visible {
  outline: var(--hairline) solid var(--focus);
  outline-offset: 4px;
}

/* -------------------------------------------------------------------------- */
/* Home                                                                       */

.cover {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  background: var(--paper);
}

.cover__media {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.cover__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 72% 40%;
  mix-blend-mode: multiply;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 56px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 56px), transparent 100%);
}

.cover__veil {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 1;
  height: 62%;
  pointer-events: none;
  background: linear-gradient(
    to top,
    rgba(253, 253, 252, 0.92) 0%,
    rgba(253, 253, 252, 0.74) 55%,
    rgba(253, 253, 252, 0) 100%
  );
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  -webkit-mask-image: linear-gradient(to top, #000 0%, #000 55%, transparent 100%);
  mask-image: linear-gradient(to top, #000 0%, #000 55%, transparent 100%);
}

.cover__content {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  width: 100%;
  max-width: 1120px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 2.5rem var(--pad);
}

.cover__text {
  width: 100%;
  max-width: none;
}

.cover__title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: 0;
  color: var(--sand-12);
  text-wrap: balance;
}

.cover__subtitle {
  margin-top: 1.1rem;
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--ink-secondary);
}

.cover__actions {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: clamp(2.5rem, 5vh, 4rem);
  padding-top: 1.25rem;
  border-top: var(--hairline) solid var(--rule-strong);
}

.cover__start {
  display: inline-flex;
  align-items: baseline;
  gap: 0.7rem;
  min-height: 2.75rem;
  font-family: var(--font-ui);
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--sand-12);
}

.cover__arrow {
  font-family: var(--font-ui);
  font-weight: 400;
}

.cover__toc {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  font-family: var(--font-ui);
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--sand-12);
}

.cover__start:hover,
.cover__toc:hover {
  text-decoration: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.35em;
}

.cover__toc:hover {
  color: var(--sand-12);
}

.contents {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(4rem, 9vh, 6rem) 0;
}

.contents__inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--pad);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.section-head::after {
  content: "";
  flex: 1;
  height: var(--hairline);
  background: var(--rule-strong);
}

.section-head__label {
  font-family: var(--font-ui);
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: var(--sand-12);
}

.toc {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(7, auto);
  grid-auto-flow: column;
  column-gap: 1rem;
  margin-top: 2rem;
}

.toc__item--wide {
  grid-column: 1 / -1;
}

.toc__row {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  column-gap: 0.875rem;
  align-items: baseline;
  padding: 1.15rem 0;
  border-bottom: var(--hairline) solid var(--rule);
}

.toc__num {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: 1.6;
  letter-spacing: 0.08em;
  color: var(--ink-secondary);
  text-align: right;
}

.toc__title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  line-height: 1.5;
  color: var(--sand-12);
}

.toc__row:hover .toc__title,
.toc__row:focus-visible .toc__title {
  text-decoration: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.35em;
}

/* -------------------------------------------------------------------------- */
/* Reading                                                                    */

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 30;
  padding: 0.625rem 0.875rem;
  background: var(--sand-1);
  border: var(--hairline) solid var(--sand-8);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--sand-12);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

.progress {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  height: var(--hairline);
  pointer-events: none;
}

.progress__fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--sage-9);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.read-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: var(--hairline) solid var(--rule-strong);
}

.read-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--pad));
  height: 56px;
  margin: 0 auto;
  padding: 0 var(--pad);
}

.read-header__brand {
  font-family: var(--font-display);
  font-size: 0.875rem;
  letter-spacing: 0.08em;
  color: var(--sand-12);
  white-space: nowrap;
}

.read-header__toc {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  letter-spacing: 0.12em;
  color: var(--ink-secondary);
}

.read-header__brand:hover,
.read-header__toc:hover {
  text-decoration: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.35em;
}

.chapter {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--pad));
  margin: 0 auto;
  padding: clamp(3.5rem, 9vh, 7rem) var(--pad) clamp(4rem, 8vh, 6rem);
}

.chapter__head {
  margin-bottom: 3rem;
}

.chapter__label {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.6;
  letter-spacing: 0.3em;
  color: var(--accent);
}

.chapter__title {
  margin-top: 0.85rem;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--sand-12);
  text-wrap: balance;
}

.chapter__rule {
  width: 1.5rem;
  height: var(--hairline);
  margin-top: 1.75rem;
  background: var(--rule-strong);
}

.chapter__head--preface .chapter__rule {
  margin-top: 1.5rem;
}

.prose p {
  margin: 0 0 0.85em;
  text-indent: 2em;
  text-align: justify;
  text-justify: inter-ideograph;
  line-break: strict;
  overflow-wrap: break-word;
}

.prose > p:last-child {
  margin-bottom: 0;
}

.prose--preface p {
  margin: 0 0 1.25em;
  font-family: var(--font-display);
  font-size: 1.75rem;
  line-height: 1.62;
  text-indent: 0;
  text-align: left;
}

.prose--preface > p:last-child {
  margin-bottom: 0;
}

.transcript {
  margin: 2.5rem 0 2.75rem;
  scroll-margin-top: 5rem;
  font-family: var(--font-ui);
  font-size: 1.125rem;
  line-height: 1.8;
  color: var(--sand-12);
}

.transcript::before {
  content: "";
  display: block;
  width: 2rem;
  height: var(--hairline);
  margin-bottom: 1.25rem;
  background: var(--rule-strong);
}

.transcript--recv {
  margin-right: 8%;
}

.transcript--send {
  margin-left: 8%;
}

.transcript p {
  margin: 0 0 1.15em;
  text-indent: 0;
  text-align: left;
}

.transcript p:last-child {
  margin-bottom: 0;
}

.dateline {
  margin: 0 0 2.5rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.9;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
}

.dateline span {
  display: block;
}

.inscription {
  margin: 2.5rem auto;
  max-width: 24em;
  font-size: 1.125rem;
  line-height: 1.9;
  text-align: center;
  text-indent: 0;
  letter-spacing: 0.05em;
  color: var(--ink-secondary);
}

.signature {
  margin: 3.5rem 0 0;
  scroll-margin-top: 5rem;
  font-family: var(--font-hand);
  font-size: 1.125rem;
  line-height: 1.9;
  text-align: right;
  letter-spacing: 0.02em;
  color: var(--sand-12);
}

.signature p {
  margin: 0;
  text-indent: 0;
  text-align: right;
}

.signature p + p {
  margin-top: 0.15em;
}

.plate {
  max-width: 540px;
  scroll-margin-top: 5rem;
  margin: 4.5rem auto 0;
}

.plate img {
  width: 100%;
  height: auto;
  mix-blend-mode: multiply;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: var(--hairline) solid var(--rule-strong);
}

.pager__item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 3.5rem;
}

.pager__item--next {
  grid-column: 2;
  align-items: flex-end;
  text-align: right;
}

.pager__label {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: 1.6;
  letter-spacing: 0.08em;
  color: var(--ink-secondary);
}

.pager__title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  line-height: 1.5;
  color: var(--sand-12);
}

.pager__item:hover .pager__title,
.pager__item:focus-visible .pager__title {
  text-decoration: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.35em;
}

/* -------------------------------------------------------------------------- */
/* 404                                                                        */

.not-found {
  display: grid;
  place-content: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: var(--pad);
  text-align: center;
}

.not-found__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.not-found__code {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  letter-spacing: 0.24em;
  color: var(--accent);
}

.not-found__title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--sand-12);
}

.not-found__link {
  margin-top: 1rem;
  font-family: var(--font-ui);
  font-size: 1.125rem;
  letter-spacing: 0.04em;
  color: var(--sand-12);
  text-decoration: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.35em;
}

/* -------------------------------------------------------------------------- */
/* Wider screens                                                              */

@media (min-width: 861px) {
  .cover__media img {
    object-position: 50% 42%;
    -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 88px), transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 88px), transparent 100%);
  }

  .cover__veil {
    inset: 0;
    height: auto;
    background: linear-gradient(
      90deg,
      rgba(253, 253, 252, 0.80) 0%,
      rgba(253, 253, 252, 0.66) 40%,
      rgba(253, 253, 252, 0.34) 60%,
      rgba(253, 253, 252, 0) 76%
    );
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    -webkit-mask-image: linear-gradient(to right, #000 0%, #000 50%, transparent 76%);
    mask-image: linear-gradient(to right, #000 0%, #000 50%, transparent 76%);
  }

  .cover__content {
    align-items: center;
    padding: clamp(2rem, 5vh, 4rem) var(--pad);
  }

  .cover__text {
    max-width: 560px;
  }

  .toc {
    column-gap: 3rem;
    margin-top: 2.5rem;
  }

  .toc__row {
    grid-template-columns: 3.5rem minmax(0, 1fr);
    column-gap: 1.25rem;
    padding: 1.35rem 0;
  }

  .contents {
    padding-top: 6rem;
  }
}

@media (max-width: 720px) {
  .transcript--recv,
  .transcript--send {
    margin-right: 0;
    margin-left: 0;
  }

  .prose--preface p {
    font-size: 1.125rem;
    line-height: 1.85;
  }

  .chapter {
    padding-top: clamp(2.75rem, 7vh, 4rem);
  }

  .chapter__head {
    margin-bottom: 2.5rem;
  }

  .pager {
    gap: 1.25rem;
  }

  .plate {
    margin-top: 3rem;
  }

  .signature {
    margin-top: 2.75rem;
  }
}

@media print {
  .skip-link,
  .progress,
  .read-header,
  .pager {
    display: none;
  }

  body {
    background: var(--sand-1);
    color: var(--sand-12);
  }

  .chapter {
    max-width: none;
    padding: 0;
  }

  .prose p {
    orphans: 2;
    widows: 2;
  }

  .plate {
    break-inside: avoid;
  }
}
