:root {
  --paper: #fdfbf7;
  --panel: #f5f5f5;
  --ink: #1a1a1a;
  --line: #e0e0e0;
  --mute: #5c5c5c;
  --rail: 252px;
  --side-pad: clamp(20px, 5vw, 64px);
  --radius: 10px;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 17px;
  line-height: 1.75;
  font-weight: 400;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
}

img {
  max-width: 100%;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* ---------- 左侧固定导航 ---------- */
.rail {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--rail);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 26px 18px 22px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.brand {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--ink);
  padding: 6px 4px;
  min-height: 42px;
}

.rail-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.rail-links a {
  display: block;
  padding: 11px 10px;
  min-height: 44px;
  font-size: 1rem;
  line-height: 1.35;
  text-decoration: none;
  color: var(--ink);
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.rail-links a:hover,
.rail-links a[aria-current] {
  background: var(--ink);
  color: var(--paper);
  border-left-color: var(--ink);
}

.search {
  display: flex;
  align-items: stretch;
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  min-height: 44px;
}

.search input::placeholder {
  color: var(--mute);
}

.search button {
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 1rem;
  padding: 0 14px;
  min-height: 44px;
  cursor: pointer;
}

.search button:hover {
  background: #000;
}

/* ---------- 主体 ---------- */
main,
footer {
  margin-left: var(--rail);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  align-items: center;
  gap: clamp(24px, 4vw, 56px);
  min-height: 70vh;
  padding: clamp(40px, 7vh, 84px) var(--side-pad);
  border-bottom: 1px solid var(--ink);
}

.hero-plain {
  grid-template-columns: minmax(0, 1fr);
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5.6vw, 4.2rem);
  line-height: 1.06;
  letter-spacing: -0.035em;
  font-weight: 700;
  max-width: 14ch;
  text-wrap: balance;
}

.hero-plates {
  position: relative;
  height: clamp(240px, 46vh, 420px);
  will-change: transform;
}

.plate {
  position: absolute;
  margin: 0;
  padding: 7px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 7px 7px 0 rgba(26, 26, 26, 0.08);
}

.plate-a {
  top: 0;
  left: 0;
  width: 66%;
}

.plate-b {
  right: 0;
  bottom: 0;
  width: 58%;
}

.plate-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
  filter: grayscale(1) contrast(1.06);
}

.wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 246px;
  grid-template-areas: "body side";
  gap: clamp(24px, 4vw, 56px);
  max-width: 1180px;
  padding: clamp(32px, 5vw, 64px) var(--side-pad);
}

.body {
  grid-area: body;
  min-width: 0;
}

article section[id] {
  scroll-margin-top: 22px;
}

article section {
  padding-bottom: 1.6rem;
  margin-bottom: 2.6rem;
  border-bottom: 1px solid var(--line);
}

article section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

article h2 {
  margin: 0 0 0.7em;
  padding-top: 0.7em;
  border-top: 2px solid var(--ink);
  font-size: clamp(1.45rem, 2.8vw, 1.95rem);
  line-height: 1.25;
  letter-spacing: -0.015em;
}

article h3 {
  margin: 1.8em 0 0.5em;
  font-size: 1.18rem;
  line-height: 1.4;
}

article h4 {
  margin: 1.4em 0 0.4em;
  font-size: 1.05rem;
}

article p {
  margin: 0 0 1.05em;
  max-width: 66ch;
  font-size: 1rem;
}

article ul,
article ol {
  margin: 0 0 1.2em;
  padding-left: 1.35em;
  max-width: 66ch;
}

article li {
  margin: 0.4em 0;
  font-size: 1rem;
}

article a {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

article a:hover {
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
}

article strong {
  font-weight: 700;
}

article blockquote {
  margin: 1.6em 0;
  padding: 0.2em 0 0.2em 1.1em;
  border-left: 3px solid var(--ink);
  color: var(--mute);
}

article blockquote p {
  margin-bottom: 0.6em;
}

article table {
  width: 100%;
  margin: 1.4em 0;
  border-collapse: collapse;
  font-size: 1rem;
  display: block;
  overflow-x: auto;
}

article th,
article td {
  border: 1px solid var(--line);
  padding: 0.6em 0.8em;
  text-align: left;
  vertical-align: top;
}

article th {
  background: var(--panel);
  font-weight: 700;
}

article code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
  background: var(--panel);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.2em 0;
}

article time {
  font-variant-numeric: tabular-nums;
  color: var(--mute);
}

article figure {
  margin: 1.6em 0;
}

article figure img {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  filter: grayscale(1) contrast(1.05);
}

article figcaption {
  margin-top: 0.5em;
  font-size: 1rem;
  color: var(--mute);
}

/* ---------- 右侧索引 ---------- */
.side {
  grid-area: side;
  position: sticky;
  top: 26px;
  align-self: start;
  padding: 20px 18px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-bottom: 3px solid var(--ink);
}

.side h2 {
  margin: 0 0 0.15em;
  font-size: 1.1rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.side .subtitle {
  margin: 0 0 1em;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--mute);
}

.side ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: idx;
}

.side li {
  counter-increment: idx;
  border-bottom: 1px solid var(--line);
}

.side li:last-child {
  border-bottom: 0;
}

.side li a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 10px 6px;
  min-height: 44px;
  font-size: 1rem;
  line-height: 1.4;
  text-decoration: none;
  color: var(--ink);
  border-radius: var(--radius);
}

.side li a::before {
  content: counter(idx, decimal-leading-zero);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--mute);
}

.side li a:hover {
  background: var(--ink);
  color: var(--paper);
}

.side li a:hover::before {
  color: var(--paper);
}

/* ---------- 页脚 ---------- */
footer {
  border-top: 2px solid var(--ink);
  padding: clamp(28px, 4vw, 48px) var(--side-pad) clamp(24px, 3vw, 36px);
  background: var(--paper);
}

.foot-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px 32px;
}

.foot-mark {
  font-size: clamp(1.9rem, 4.6vw, 3.2rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  text-decoration: none;
  color: var(--ink);
}

.foot-mark:hover {
  background: var(--ink);
  color: var(--paper);
}

.foot-nav dl {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
}

.foot-nav dt {
  margin: 0;
}

.foot-nav a {
  display: inline-block;
  padding: 9px 2px;
  min-height: 44px;
  font-size: 1rem;
  line-height: 1.4;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid transparent;
}

.foot-nav a:hover {
  border-bottom-color: var(--ink);
}

.foot-copy {
  margin: 0;
  font-size: 1rem;
  color: var(--mute);
}

/* ---------- 响应式 ---------- */
@media (max-width: 880px) {
  .rail {
    position: static;
    width: auto;
    height: auto;
    gap: 12px;
    padding: 14px 16px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    min-height: 40px;
    padding: 0;
  }

  .rail-links {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .rail-links a {
    padding: 10px 12px;
    min-height: 44px;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  .rail-links a:hover,
  .rail-links a[aria-current] {
    border-color: var(--ink);
  }

  .search {
    margin-top: 0;
  }

  main,
  footer {
    margin-left: 0;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    gap: 26px;
    padding: 30px 16px 36px;
  }

  .hero h1 {
    font-size: clamp(1.9rem, 8.2vw, 2.7rem);
    max-width: none;
  }

  .hero-plates {
    height: 230px;
  }

  .wrap {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "side" "body";
    gap: 26px;
    padding: 26px 16px 44px;
  }

  .side {
    position: static;
  }

  footer {
    padding: 26px 16px 34px;
  }

  .foot-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .hero-plates {
    transform: none !important;
  }
}

button[aria-expanded]{min-width:44px;min-height:44px}
