/* ─── Design tokens ──────────────────────────────────────────────────────── */

:root {
  --paper: #f5f0e5;
  --paper-raised: #fbf8f0;
  --ink: #24201a;
  --muted: #71675c;
  --line: #cbbda9;
  --line-faint: rgba(112, 94, 70, 0.045);
  --seal: #9f3025;
  --seal-dark: #7c241d;
  --max: 1140px;
  --read: 720px;
  --serif: Georgia, "Times New Roman", "Noto Serif SC", "Songti SC", SimSun, serif;
  --sans: "Segoe UI", "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

/* ─── Dark mode ──────────────────────────────────────────────────────────── */

/* Explicit toggle via JS */
body.theme-dark {
  color-scheme: dark;
  --paper: #171512;
  --paper-raised: #211e19;
  --ink: #eee6d8;
  --muted: #b9ab99;
  --line: #5d5146;
  --line-faint: rgba(180, 155, 120, 0.06);
  --seal: #d46b56;
  --seal-dark: #ef9c88;
}

/* OS-level dark preference (no JS or first paint before JS runs) */
@media (prefers-color-scheme: dark) {
  body:not(.theme-light) {
    color-scheme: dark;
    --paper: #171512;
    --paper-raised: #211e19;
    --ink: #eee6d8;
    --muted: #b9ab99;
    --line: #5d5146;
    --line-faint: rgba(180, 155, 120, 0.06);
    --seal: #d46b56;
    --seal-dark: #ef9c88;
  }
}

/* ─── Base ───────────────────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  color-scheme: light;
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.78;
  text-rendering: optimizeLegibility;
}

/* Subtle vertical grid line texture */
body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  content: "";
  opacity: 0.32;
  pointer-events: none;
  background-image: linear-gradient(
    90deg,
    transparent 49.9%,
    var(--line-faint) 50%,
    transparent 50.1%
  );
  background-size: 14rem 100%;
}

a {
  color: var(--seal-dark);
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.16em;
}

a:hover {
  color: var(--seal);
}

img {
  max-width: 100%;
  height: auto;
}

p, h1, h2, h3, .lead {
  overflow-wrap: break-word;
}

/* ─── Header & nav ───────────────────────────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: min(var(--max), calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.68rem;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.brand img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem 1.05rem;
  font-family: var(--sans);
  font-size: 0.86rem;
}

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

.nav a[aria-current="page"],
.nav a:hover {
  color: var(--ink);
}

.language-link {
  margin-left: 0.35rem;
  padding-left: 1rem;
  border-left: 1px solid var(--line);
}

/* ─── Layout helpers ─────────────────────────────────────────────────────── */

.wrap {
  width: min(var(--max), calc(100% - 2rem));
  margin: 0 auto;
}

/* ─── Hero ───────────────────────────────────────────────────────────────── */

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 0.62fr);
  gap: clamp(2rem, 7vw, 8rem);
  align-items: center;
  min-height: calc(100vh - 75px);
  padding: 4.2rem 0 5.2rem;
}

.hero-inner {
  max-width: 710px;
}

.eyebrow,
.meta {
  margin: 0 0 0.8rem;
  color: var(--seal-dark);
  font-family: var(--sans);
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 500;
  line-height: 1.16;
}

h1 {
  max-width: 9ch;
  font-size: 2.8rem;
}

h2 {
  font-size: 1.9rem;
}

h3 {
  font-size: 1.3rem;
}

.lead {
  max-width: 650px;
  margin: 1.4rem 0 0;
  color: var(--muted);
  font-size: clamp(1.1rem, 2vw, 1.42rem);
  line-height: 1.68;
}

.hero-mark {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 22rem;
}

.hero-mark::before {
  position: absolute;
  width: min(25rem, 100%);
  aspect-ratio: 1;
  content: "";
  border: 1px solid var(--line);
  border-radius: 50%;
}

.hero-mark::after {
  position: absolute;
  width: 74%;
  aspect-ratio: 1;
  content: "";
  border: 1px solid color-mix(in srgb, var(--seal) 46%, transparent);
  border-radius: 50%;
}

.hero-mark img {
  position: relative;
  z-index: 1;
  width: min(20rem, 75%);
  border-radius: 50%;
  mix-blend-mode: multiply;
}

body.theme-dark .hero-mark img,
.title-lockup img {
  mix-blend-mode: screen;
  opacity: 0.9;
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .hero-mark img {
    mix-blend-mode: screen;
    opacity: 0.9;
  }
}

.hero-note {
  position: absolute;
  right: 0;
  bottom: 0;
  max-width: 15rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.76rem;
  line-height: 1.55;
}

/* ─── Buttons & links ────────────────────────────────────────────────────── */

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1.8rem;
  font-family: var(--sans);
  font-size: 0.9rem;
}

.button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  padding: 0.42rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}

.button {
  border-color: var(--seal);
  background: var(--seal);
  color: #fffaf0;
}

.button:hover {
  border-color: var(--seal-dark);
  background: var(--seal-dark);
  color: #fffaf0;
}

.text-button:hover,
.reader-tools .button:hover {
  border-color: var(--seal);
  color: var(--seal-dark);
}

/* ─── Sections ───────────────────────────────────────────────────────────── */

.section {
  position: relative;
  padding: clamp(3.4rem, 8vw, 6.5rem) 0;
}

.section::before,
.site-footer::before {
  display: block;
  width: 100%;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--line) 14%, var(--line) 86%, transparent);
}

.section-head {
  display: grid;
  grid-template-columns: minmax(180px, 0.42fr) minmax(280px, 1fr);
  gap: clamp(1rem, 4vw, 3.5rem);
  align-items: start;
  margin-top: clamp(2rem, 5vw, 3.7rem);
  margin-bottom: 2.1rem;
}

.section-head p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
}

.feature-work {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(210px, 0.7fr);
  gap: clamp(1.4rem, 4vw, 4rem);
  align-items: end;
  padding: clamp(1.4rem, 4vw, 2.8rem) 0 0;
  border-top: 1px solid var(--line);
}

.feature-work h3 {
  font-size: 2.25rem;
}

.feature-work p {
  max-width: 39rem;
  margin: 1rem 0 0;
  color: var(--muted);
}

.work-facts {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--sans);
  font-size: 0.82rem;
}

.work-facts li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.65rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  color: var(--muted);
}

.work-facts span:last-child {
  color: var(--ink);
  text-align: right;
}

/* ─── Grid & panels ──────────────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.panel {
  min-height: 100%;
  padding: 1.2rem 1.25rem;
  border: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--paper-raised) 52%, transparent);
}

.panel p,
.panel ul {
  margin-bottom: 0;
  color: var(--muted);
}

.panel h3 + p {
  margin-top: 0.7rem;
}

/* ─── Page title ─────────────────────────────────────────────────────────── */

.page-title {
  padding: clamp(3rem, 7vw, 5.2rem) 0 clamp(1.6rem, 4vw, 3rem);
}

.page-title h1 {
  max-width: 12ch;
  font-size: 2.6rem;
}

.page-title .lead {
  max-width: 760px;
}

.title-lockup {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.title-lockup img {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  object-fit: cover;
  mix-blend-mode: multiply;
}

/* ─── Content list ───────────────────────────────────────────────────────── */

.content-list {
  display: grid;
  gap: 1.2rem;
}

.content-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(7rem, 0.22fr) minmax(0, 1fr);
  gap: 1.2rem;
  padding: 1.5rem 0;
}

.content-item::before,
.term::before {
  position: absolute;
  top: 0;
  left: 0;
  width: min(18rem, 48%);
  height: 1px;
  content: "";
  background: linear-gradient(90deg, var(--line), transparent);
}

.content-item time,
.content-item .label,
.chapter-meta {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.82rem;
}

.content-item p {
  margin: 0.55rem 0 0;
  color: var(--muted);
}

/* ─── Article / reader shell ─────────────────────────────────────────────── */

.article-shell {
  display: grid;
  grid-template-columns: minmax(130px, 190px) minmax(0, var(--read)) minmax(130px, 1fr);
  gap: clamp(1rem, 4vw, 3rem);
  width: min(1280px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 3rem 0 5rem;
}

.reader-tools,
.toc {
  position: sticky;
  top: 1rem;
  align-self: start;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--muted);
}

.reader-tools {
  display: grid;
  gap: 0.45rem;
}

.reader-tools button {
  width: 100%;
}

.reader-tools .button {
  background: transparent;
  color: var(--ink);
}

.toc nav {
  display: grid;
  gap: 0.38rem;
}

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

.toc a:hover {
  color: var(--seal-dark);
}

.article {
  width: 100%;
  max-width: var(--read);
  font-size: var(--reader-font, 20px);
  line-height: var(--reader-leading, 1.86);
}

.article h1 {
  max-width: none;
  margin-bottom: 1rem;
  font-size: 2.35rem;
}

.article h2 {
  margin-top: 3.4rem;
  margin-bottom: 1rem;
  font-size: 1.65rem;
}

.article p {
  margin: 0 0 1.25rem;
}

.article .note {
  padding: 1rem 1.1rem;
  border-left: 3px solid var(--seal);
  background: color-mix(in srgb, var(--seal) 6%, transparent);
  color: var(--muted);
  font-size: 0.94em;
}

.footnotes {
  margin-top: 3.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9em;
}

/* ─── Definition list ────────────────────────────────────────────────────── */

.definition-list {
  display: grid;
  gap: 1rem;
}

.term {
  position: relative;
  padding: 1.2rem 0;
}

.term dt {
  margin: 0 0 0.35rem;
  color: var(--ink);
  font-size: 1.28rem;
}

.term dd {
  margin: 0;
  color: var(--muted);
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  position: relative;
  width: min(var(--max), calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.5rem 0 3rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.82rem;
}

.footer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1rem;
  justify-content: space-between;
  padding-top: 0.85rem;
}

.visit-counter:empty,
.visit-counter[data-unavailable="true"] {
  display: none;
}

/* ─── Responsive: tablet ─────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav {
    justify-content: flex-start;
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 3.8rem 0 4.7rem;
  }

  .hero-mark {
    order: -1;
    min-height: 14rem;
  }

  .hero-mark::before {
    width: 14rem;
  }

  .hero-mark img {
    width: 10.5rem;
  }

  .hero-note {
    display: none;
  }

  .section-head,
  .feature-work {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .article-shell {
    grid-template-columns: 1fr;
    width: min(var(--read), calc(100% - 2rem));
    max-width: calc(100% - 2rem);
  }

  .reader-tools,
  .toc {
    position: static;
  }

  .reader-tools {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .content-item {
    grid-template-columns: 1fr;
  }
}

/* ─── Responsive: mobile ─────────────────────────────────────────────────── */

@media (max-width: 520px) {
  body {
    font-size: 17px;
  }

  .nav {
    gap: 0.3rem 0.8rem;
  }

  .article {
    font-size: var(--reader-font, 19px);
  }

  .page-title h1,
  h1 {
    font-size: 2.35rem;
  }

  .reader-tools {
    grid-template-columns: 1fr;
  }
}
