@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&family=Share+Tech+Mono&display=swap');

:root {
  --ink: #000000;
  --paper: #ffffff;
  --mono: 'Fira Code', 'Share Tech Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --pad: clamp(1.25rem, 4vw, 4.5rem);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*,
*::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: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.75;
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: start;
}

img { max-width: 100%; }

/* ---------- 左侧固定栏 ---------- */

.rail {
  grid-column: 1;
  grid-row: 1 / span 2;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  padding: 1.6rem 1.35rem;
  background: var(--paper);
  border-right: 1px solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: -.02em;
}

.brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  display: block;
}

.drawer { margin-top: auto; }

.drawer summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 44px;
  padding: .4rem 0;
  border-bottom: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: .8rem;
  letter-spacing: .32em;
}

.drawer summary::-webkit-details-marker { display: none; }

.drawer summary::after {
  content: "＋";
  font-size: .95rem;
  letter-spacing: 0;
}

.drawer[open] summary::after { content: "－"; }

.drawer menu {
  list-style: none;
  margin: 0;
  padding: .2rem 0 0;
  counter-reset: m;
}

.drawer li { counter-increment: m; }

.drawer a {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 42px;
  padding: .35rem 0;
  color: inherit;
  text-decoration: none;
  font-size: .95rem;
  border-bottom: 1px solid rgba(0, 0, 0, .16);
  transition: padding-left .2s var(--ease);
}

.drawer a::before {
  content: counter(m, decimal-leading-zero);
  font-family: var(--mono);
  font-size: .68rem;
  opacity: .5;
}

.drawer a:hover { padding-left: .4rem; }

.cta {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 .75rem;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  text-decoration: none;
  font-family: var(--mono);
  font-size: .85rem;
  letter-spacing: .04em;
  transition: background .22s var(--ease), color .22s var(--ease);
}

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

/* ---------- 主体 ---------- */

main {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

main > section {
  padding: clamp(2.5rem, 6vw, 5rem) var(--pad);
  scroll-margin-top: 1.25rem;
}

main > section + section { border-top: 1px solid var(--ink); }

main > section:not(.hero) > * { max-width: 66ch; }

/* ---------- 首屏 ---------- */

.hero {
  background: var(--ink);
  color: var(--paper);
  min-height: 70vh;
  display: grid;
  align-items: center;
  gap: clamp(1rem, 2.5vw, 2rem) 1.5rem;
  grid-template-columns: minmax(0, 1fr) 7rem 12rem;
  grid-template-areas:
    "badge badge toc"
    "h1 fig toc";
}

.hero h1 {
  grid-area: h1;
  margin: 0;
  font-family: var(--mono);
  font-weight: 900;
  font-size: clamp(2.6rem, 8vw, 8.5rem);
  line-height: .95;
  letter-spacing: -.05em;
  overflow-wrap: anywhere;
  max-width: 14ch;
}

.badge {
  grid-area: badge;
  justify-self: start;
  align-self: end;
  border: 1px solid currentColor;
  padding: .3rem .55rem;
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .2em;
}

.hud {
  grid-area: fig;
  margin: 0;
  align-self: start;
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid currentColor;
  overflow: hidden;
}

.hud::before,
.hud::after {
  content: "";
  position: absolute;
  background: currentColor;
  opacity: .65;
  z-index: 2;
}

.hud::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
}

.hud::after {
  top: 50%;
  left: 0;
  height: 1px;
  width: 100%;
}

.hud-dot {
  position: absolute;
  z-index: 3;
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  animation: pulse 2.6s infinite ease-in-out;
}

.hud img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(2.6); opacity: .3; }
}

/* ---------- 右侧目录 ---------- */

.toc {
  grid-area: toc;
  align-self: start;
  border: 1px solid currentColor;
  padding: .9rem 1rem 1.1rem;
}

.toc h2 {
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 400;
  letter-spacing: .34em;
  margin: 0 0 .5rem;
}

.toc hr {
  border: 0;
  border-top: 1px solid currentColor;
  opacity: .55;
  margin: 0 0 .4rem;
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: t;
}

.toc li { counter-increment: t; }

.toc a {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 38px;
  padding: .3rem 0;
  color: inherit;
  text-decoration: none;
  font-size: .88rem;
  border-bottom: 1px solid rgba(255, 255, 255, .22);
}

.toc a::before {
  content: counter(t, decimal-leading-zero);
  font-family: var(--mono);
  font-size: .66rem;
  opacity: .55;
}

.toc a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 正文排版 ---------- */

main h2 {
  font-family: var(--mono);
  font-weight: 900;
  font-size: clamp(1.7rem, 4.2vw, 3.1rem);
  line-height: 1.1;
  letter-spacing: -.04em;
  margin: 0 0 .8rem;
  overflow-wrap: anywhere;
}

main h2 + hr {
  border: 0;
  border-top: 1px solid var(--ink);
  margin: 0 0 1.6rem;
}

main hr {
  border: 0;
  border-top: 1px solid var(--ink);
  margin: 1.6rem 0;
}

main h3 {
  font-family: var(--mono);
  font-size: 1.2rem;
  letter-spacing: -.01em;
  margin: 2rem 0 .6rem;
}

main p { margin: 0 0 1.1rem; }

main ul,
main ol {
  margin: 0 0 1.2rem;
  padding-left: 1.35em;
}

main li { margin: .35rem 0; }

main a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

main a:hover { background: var(--ink); color: var(--paper); }

main blockquote {
  margin: 1.5rem 0;
  padding-left: 1.1rem;
  border-left: 3px solid var(--ink);
  font-size: 1.05rem;
}

main img { height: auto; }

/* ---------- 页脚 ---------- */

.foot {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem 2rem;
  padding: clamp(2rem, 5vw, 3.5rem) var(--pad) 1.75rem;
  border-top: 1px solid var(--ink);
}

.foot-brand {
  margin: 0;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.02em;
}

.foot-links { margin: 0; }

.foot-links a {
  display: inline-block;
  min-height: 40px;
  padding: .5rem 0;
  margin-right: 1.1rem;
  color: inherit;
  text-decoration: none;
  font-size: .92rem;
}

.foot-links a:hover { text-decoration: underline; text-underline-offset: 3px; }

.foot small {
  grid-column: 1 / -1;
  font-family: var(--mono);
  font-size: .78rem;
  letter-spacing: .06em;
  opacity: .62;
}

/* ---------- 入场动效 ---------- */

main > section[data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}

main > section[data-reveal].in {
  opacity: 1;
  transform: none;
}

.drawer[open] menu li {
  animation: rise .34s var(--ease) both;
}

.drawer[open] menu li:nth-child(2) { animation-delay: .035s; }
.drawer[open] menu li:nth-child(3) { animation-delay: .07s; }
.drawer[open] menu li:nth-child(4) { animation-delay: .105s; }
.drawer[open] menu li:nth-child(5) { animation-delay: .14s; }
.drawer[open] menu li:nth-child(6) { animation-delay: .175s; }
.drawer[open] menu li:nth-child(7) { animation-delay: .21s; }

@keyframes rise {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  main > section[data-reveal] { opacity: 1; transform: none; transition: none; }
  .hud-dot { animation: none; }
  .drawer[open] menu li { animation: none; }
  .drawer a,
  .cta { transition: none; }
}

/* ---------- 窄屏 ---------- */

@media (max-width: 1023px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }

  .rail {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: .75rem;
    padding: .5rem 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--ink);
  }

  .brand { font-size: .95rem; min-height: 44px; }
  .brand img { width: 28px; height: 28px; }

  .drawer {
    margin-top: 0;
    position: static;
  }

  .drawer summary {
    border-bottom: 0;
    padding: .4rem .6rem;
    min-height: 44px;
    letter-spacing: .22em;
  }

  .drawer menu {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    display: none;
    background: var(--ink);
    padding: .5rem 1rem 1rem;
    border-bottom: 1px solid var(--ink);
    z-index: 40;
  }

  .drawer[open] menu { display: block; }

  .drawer menu a {
    color: var(--paper);
    border-bottom: 1px solid rgba(255, 255, 255, .22);
  }

  .rail .cta {
    margin-left: auto;
    min-height: 44px;
    padding: 0 .8rem;
    font-size: .82rem;
  }

  main { grid-column: 1; grid-row: 2; }

  main > section {
    padding: 2.25rem 1.25rem;
    scroll-margin-top: 4.75rem;
  }

  .hero {
    min-height: 0;
    padding-top: 2rem;
    padding-bottom: 2.5rem;
    grid-template-columns: minmax(0, 1fr) 5.5rem;
    grid-template-areas:
      "badge badge"
      "h1 fig"
      "toc toc";
  }

  .hud { width: 5.5rem; }

  .toc { margin-top: .5rem; }

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

  .foot {
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: minmax(0, 1fr);
    padding: 2rem 1.25rem 1.5rem;
    gap: 1rem;
  }

  .foot small { grid-column: 1; }
}

@media (max-width: 420px) {
  .hero h1 { font-size: clamp(2.3rem, 11vw, 3.4rem); }
  .brand span { max-width: 7em; overflow-wrap: anywhere; line-height: 1.1; }
}

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