:root {
  --bg: #f6f7f7;
  --paper: #ffffff;
  --text: #0f141a;
  --text-2: rgba(15, 20, 26, 0.72);
  --text-3: rgba(15, 20, 26, 0.46);
  --accent: #267ef0;
  --accent-soft: rgba(38, 126, 240, 0.08);
  --border: rgba(6, 15, 26, 0.08);
  --border-strong: rgba(6, 15, 26, 0.14);
  --sidebar: #f6f7f7;
  --header-h: 56px;
  --sidebar-w: 268px;
  --callout: #f4f8ff;
  --code-bg: rgba(6, 15, 26, 0.06);
  --shadow: 0 1px 0 rgba(6, 15, 26, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.75;
  user-select: text;
  -webkit-user-select: text;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

.header {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px 0 8px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  z-index: 40;
  gap: 8px;
}
.header-home {
  width: 40px; height: 40px;
  border: 0; background: transparent; border-radius: 8px;
  display: grid; place-items: center; color: var(--text);
  cursor: default;
}
.header-divider { width: 1px; height: 16px; background: var(--border-strong); margin: 0 4px; }
.header-title {
  font-weight: 700; font-size: 14px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.btn-short { display: none; }
.menu-btn {
  display: none;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
}
.header-badge {
  margin-left: 8px;
  font-size: 12px; color: #b8821a;
  background: #fff6de; border: 1px solid #f3e0a8;
  border-radius: 4px; padding: 2px 8px; white-space: nowrap;
}
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.btn {
  height: 32px; padding: 0 12px; border-radius: 6px;
  border: 1px solid transparent; background: transparent;
  color: var(--text); font-size: 13px; cursor: pointer;
}
.btn-ghost { border-color: var(--border-strong); background: #fff; }
.btn-primary { background: var(--accent); color: #fff; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #1f6feb; color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}

.layout {
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
}

.sidebar {
  height: 100%;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  padding: 14px 12px 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-doc-title { font-weight: 700; font-size: 14px; }
.sidebar-section-label {
  padding: 8px 16px 6px;
  font-size: 12px; color: var(--text-3); font-weight: 600;
}
.sidebar-nav { flex: 1; overflow: auto; padding: 0 8px 12px; }
.page-item {
  display: flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 8px 8px; border-radius: 6px;
  color: var(--text-2); font-size: 13px; cursor: default;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  line-height: 1.35;
  appearance: none;
  -webkit-appearance: none;
}
.page-item[data-page] { cursor: pointer; }
.page-item[data-page]:hover { background: rgba(6, 15, 26, 0.04); }
.page-item.active {
  background: rgba(6, 15, 26, 0.06);
  color: var(--text); font-weight: 600;
}
.page-icon {
  flex: 0 0 16px;
  width: 16px;
  height: 18px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  position: relative;
  color: var(--text-3);
  background:
    linear-gradient(currentColor, currentColor) 4px 6px / 8px 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 10px / 6px 1.5px no-repeat;
}
.page-item.active .page-icon {
  color: var(--accent);
  background:
    linear-gradient(#fff, #fff) 4px 6px / 8px 1.5px no-repeat,
    linear-gradient(#fff, #fff) 4px 10px / 6px 1.5px no-repeat,
    var(--accent);
  border-color: var(--accent);
}
.toc {
  margin: 4px 0 10px 28px;
  border-left: 1px solid var(--border-strong);
  padding-left: 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.toc[hidden] { display: none; }
.toc a {
  color: var(--text-2); font-size: 12.5px; line-height: 1.45;
  padding: 4px 6px; border-radius: 4px; text-decoration: none;
}
.toc a:hover, .toc a.active { background: rgba(38, 126, 240, 0.08); color: var(--accent); }
.toc a.l2 { padding-left: 14px; color: var(--text-3); }
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px 14px;
  color: var(--text-3); font-size: 13px;
}
.sidebar-foot div { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px; }

.main {
  min-width: 0;
  background: var(--bg);
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.paper {
  max-width: 980px;
  margin: 0 auto;
  background: var(--paper);
  min-height: calc(100dvh - var(--header-h));
  padding: 36px 64px 96px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  overflow-wrap: anywhere;
  word-break: break-word;
}
.doc-kicker {
  font-size: 12px; color: var(--text-3); letter-spacing: 0.04em; margin-bottom: 8px;
}
h1.doc-title {
  font-size: 32px; line-height: 1.3; font-weight: 700;
  margin: 0 0 20px; letter-spacing: -0.02em;
}
.lead {
  background: var(--callout);
  border: 1px solid rgba(38, 126, 240, 0.14);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--text-2);
  margin: 0 0 28px;
}
h2 {
  font-size: 24px; line-height: 1.35; margin: 40px 0 14px;
  padding-top: 8px;
  scroll-margin-top: 16px;
}
h3 {
  font-size: 18px; line-height: 1.4; margin: 28px 0 10px;
  scroll-margin-top: 16px;
}
h4 {
  font-size: 15.5px; line-height: 1.45; margin: 20px 0 8px;
}
p { margin: 0 0 12px; color: var(--text); }
ul { margin: 0 0 14px; padding-left: 22px; }
li { margin: 4px 0; }
.figure {
  margin: 12px 0 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  isolation: isolate;
  position: relative;
  z-index: 1;
}
.figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  background: #fff;
  object-fit: contain;
  vertical-align: middle;
}
.figure figcaption {
  font-size: 12px; color: var(--text-3);
  padding: 8px 12px 10px; background: #fff;
  border-top: 1px solid var(--border);
}
code {
  font-family: ui-monospace, "SF Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  background: var(--code-bg);
  border-radius: 4px;
  padding: 1px 5px;
}
.link-chip {
  display: inline-flex; align-items: center;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 4px; padding: 0 6px; font-size: 13px;
}
.note {
  color: var(--text-3); font-size: 13px; margin: 8px 0 16px;
}
.comments {
  margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border);
  color: var(--text-3); font-size: 13px;
}
.end-flag {
  margin-top: 8px; padding: 12px 14px;
  background: #fafafa; border: 1px dashed var(--border-strong);
  border-radius: 8px; color: var(--text-3); font-size: 13px;
}
.paper[hidden] { display: none; }
ol { margin: 0 0 14px; padding-left: 22px; }
ol li { margin: 4px 0; }
.code-block {
  margin: 0 0 16px;
  background: #0f141a;
  color: #e8edf2;
  border-radius: 10px;
  padding: 12px 14px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.55;
}
.code-block code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
  white-space: pre;
}
.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 18px;
  font-size: 14px;
}
.doc-table th,
.doc-table td {
  border: 1px solid var(--border-strong);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.doc-table th {
  background: #f4f8ff;
  font-weight: 650;
}
.field-list { margin: 0 0 14px; padding-left: 0; list-style: none; }
.field-list li { margin: 6px 0; }
.subhead-note { color: var(--text-2); margin: 0 0 12px; }

.nailong-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  background: #140800;
  cursor: pointer;
  overflow: hidden;
}
.nailong-overlay.is-on {
  display: block;
}
.nl-wall {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  opacity: 0.72;
  filter: contrast(1.15) saturate(1.25);
}
.nl-wall img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.nl-hero {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  width: min(88vw, 86dvh);
  height: min(88vw, 86dvh);
  object-fit: contain;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 0 28px rgba(0,0,0,0.85));
  animation: nl-pulse 0.28s steps(2) infinite;
}
.nl-sats img {
  position: absolute;
  z-index: 3;
  width: min(34vw, 240px);
  height: auto;
  pointer-events: none;
  animation: nl-bounce 0.42s ease-in-out infinite alternate;
}
.nl-sats img:nth-child(1) { left: 2vw; top: 6vh; animation-name: nl-spin; animation-duration: 1.1s; animation-timing-function: linear; animation-direction: normal; }
.nl-sats img:nth-child(2) { right: 2vw; top: 10vh; animation-delay: 0.08s; }
.nl-sats img:nth-child(3) { left: 4vw; bottom: 8vh; animation-delay: 0.12s; transform: scaleX(-1); }
.nl-sats img:nth-child(4) { right: 3vw; bottom: 7vh; animation-name: nl-spin; animation-duration: 0.9s; animation-timing-function: linear; animation-direction: reverse; }
.nl-sats img:nth-child(5) { left: 38vw; top: 2vh; width: min(22vw, 150px); animation-delay: 0.18s; }
.nl-sats img:nth-child(6) { left: 40vw; bottom: 3vh; width: min(22vw, 150px); animation-delay: 0.22s; }
@keyframes nl-spin { to { transform: rotate(360deg); } }
@keyframes nl-bounce {
  from { transform: translateY(0) rotate(-10deg) scale(1); }
  to { transform: translateY(-16px) rotate(12deg) scale(1.08); }
}
@keyframes nl-pulse {
  from { transform: translate(-50%, -50%) scale(1); }
  to { transform: translate(-50%, -50%) scale(1.04); }
}
.nailong-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 4;
  text-align: center;
  color: rgba(255,255,255,0.9);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 8px #000;
}

.btn { cursor: pointer; }
.btn:disabled { opacity: 0.6; cursor: wait; }

body.locked .header,
body.locked .layout { visibility: hidden; pointer-events: none; }

body.unlocked {
  background-color: #ffe566;
}
body.unlocked .main {
  background-color: #ffe14a;
  background-image:
    url("./assets/nl-spin.gif"),
    url("./assets/nailong-yellow.gif"),
    url("./assets/nailong.gif"),
    url("./assets/nl-tongue2.gif");
  background-size: 210px 210px, 168px 168px, 148px 148px, 132px 132px;
  background-repeat: repeat, repeat, repeat, repeat;
  background-position: 0 0, 105px 80px, 40px 170px, 160px 40px;
}
body.unlocked .sidebar {
  background-image: url("./assets/nl-spin.gif"), url("./assets/nailong.gif");
  background-size: 140px 140px, 110px 110px;
  background-repeat: repeat, repeat;
  background-position: 0 0, 70px 70px;
  background-color: #fff3b0;
}
body.unlocked .paper {
  position: relative;
  background-color: #fff6c2;
  isolation: isolate;
}
body.unlocked .paper::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("./assets/nl-spin.gif"), url("./assets/nl-tongue.gif"), url("./assets/nailong-yellow.gif");
  background-size: 160px 160px, 120px 120px, 140px 140px;
  background-repeat: repeat;
  background-position: 0 0, 80px 60px, 40px 120px;
  opacity: 0.28;
  pointer-events: none;
  z-index: 0;
}
body.unlocked .paper > * {
  position: relative;
  z-index: 1;
}
body.unlocked .header {
  background:
    linear-gradient(rgba(255, 252, 220, 0.88), rgba(255, 252, 220, 0.88)),
    url("./assets/nl-shock.gif") right center / 56px 56px no-repeat,
    #fffcdc;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  background: #ffe14a;
  overflow: hidden;
}
.gate[hidden] { display: none; }
.gate-wall {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  z-index: 0;
  pointer-events: none;
  filter: saturate(1.2) contrast(1.05);
}
.gate-wall img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gate::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 229, 102, 0.28), rgba(255, 90, 0, 0.32));
}
.gate-float {
  position: absolute;
  width: min(26vw, 220px);
  z-index: 2;
  pointer-events: none;
  animation: gate-wiggle 0.7s ease-in-out infinite alternate;
}
.gate-float img { width: 100%; height: auto; display: block; }
.gate-f1 { left: 2vw; top: 6vh; }
.gate-f2 { right: 2vw; top: 5vh; animation-delay: 0.1s; }
.gate-f3 { left: 3vw; bottom: 8vh; animation-delay: 0.18s; }
.gate-f4 { right: 3vw; bottom: 7vh; animation-delay: 0.26s; }
.gate-f5 { left: 2vw; top: 42vh; width: min(18vw, 150px); animation-delay: 0.32s; }
.gate-f6 { right: 2vw; top: 40vh; width: min(18vw, 150px); animation-delay: 0.4s; }
@keyframes gate-wiggle {
  from { transform: rotate(-10deg) translateY(0) scale(1); }
  to { transform: rotate(12deg) translateY(-14px) scale(1.06); }
}
.gate-card {
  width: min(420px, calc(100vw - 32px));
  background: rgba(255, 253, 243, 0.92);
  border: 4px solid #111;
  border-radius: 28px;
  padding: 22px 24px 20px;
  text-align: center;
  box-shadow: 8px 8px 0 #111;
  position: relative;
  z-index: 3;
  backdrop-filter: blur(2px);
}
.gate-hero-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.gate-hero-row img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 14px;
  border: 3px solid #111;
  background: #ffe566;
}
.gate-hero {
  width: 120px !important;
  height: 120px !important;
  border-radius: 24px !important;
  animation: gate-pulse 0.35s steps(2) infinite;
}
@keyframes gate-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.07); }
}
.gate-card h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.2;
  color: #111;
}
.gate-sub { margin: 8px 0 16px; color: #5c4a12; font-weight: 700; }
.gate-form { display: grid; gap: 12px; text-align: left; }
.gate-field span {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: #111;
}
.gate-field input {
  width: 100%;
  height: 48px;
  border: 3px solid #111;
  border-radius: 16px;
  padding: 0 52px 0 14px;
  font-size: 16px;
  background: #fff8c8 url("./assets/nl-spin.gif") right 8px center / 42px 42px no-repeat;
  outline: none;
  font-family: inherit;
}
.gate-field input:focus {
  box-shadow: 0 0 0 4px rgba(255, 159, 28, 0.45);
}
.gate-field input.shake { animation: shake 0.45s; }
.gate-error { color: #d62828; font-weight: 700; margin: 0; font-size: 14px; }
.gate-btn {
  height: 48px;
  border: 3px solid #111;
  border-radius: 16px;
  background: #ff9f1c url("./assets/nailong.gif") right 10px center / 36px 36px no-repeat;
  color: #111;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 4px 4px 0 #111;
  font-family: inherit;
  padding-right: 44px;
}
.gate-btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 #111; }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.toc-drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.35);
  display: none;
}
.toc-drawer.open { display: block; }
.toc-drawer-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(320px, 86vw);
  background: #fffdf3;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  overflow: auto;
  box-shadow: 8px 0 24px rgba(0,0,0,0.18);
}
.toc-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.drawer-close {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.toc-drawer .toc {
  margin: 0;
  border: 0;
  padding: 0;
}
.toc-drawer .toc a {
  display: block;
  padding: 10px 8px;
  font-size: 15px;
}
.drawer-pages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.drawer-page {
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  text-align: left;
  padding: 0 12px;
}
.drawer-page.active {
  background: var(--accent-soft);
  border-color: rgba(38, 126, 240, 0.35);
  color: var(--accent);
}

@media (max-width: 960px) {
  :root { --header-h: 52px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .menu-btn { display: inline-flex; align-items: center; }
  .header-home,
  .header-divider,
  .header-badge,
  .header-spacer,
  .avatar { display: none; }
  .header { gap: 6px; }
  .header-title { font-size: 13px; flex: 1; }
  .header-actions { gap: 6px; flex: 0 0 auto; }
  .btn { height: 36px; padding: 0 10px; font-size: 13px; }
  .btn-full { display: none; }
  .btn-short { display: inline; }
  .paper { padding: 20px 16px 80px; }
  h1.doc-title { font-size: 24px; }
  h2 { font-size: 20px; margin-top: 28px; }
  h3 { font-size: 17px; }
  .lead { padding: 12px; font-size: 14px; }
  .gate-float { width: 84px; }
  .gate-f5, .gate-f6 { display: none; }
  .gate-hero-row img { width: 44px; height: 44px; }
  .gate-hero { width: 96px !important; height: 96px !important; }
  .gate-card {
    width: min(420px, calc(100vw - 24px));
    padding: 20px 16px 16px;
    border-radius: 22px;
    box-shadow: 5px 5px 0 #111;
  }
  .gate-card h1 { font-size: 26px; }
  .gate-btn:hover { transform: none; box-shadow: 4px 4px 0 #111; }
  body.unlocked .main {
    background-size: 130px 130px, 110px 110px, 96px 96px, 88px 88px;
    background-position: 0 0, 65px 50px, 24px 110px, 90px 24px;
  }
  body.unlocked .paper::before {
    opacity: 0.14;
    background-size: 110px 110px, 90px 90px, 100px 100px;
  }
  .nl-sats img:nth-child(n+5) { display: none; }
  .nl-sats img { width: min(38vw, 160px); }
  .nl-wall { opacity: 0.55; }
  .nailong-hint { font-size: 13px; }
}

@media (max-width: 420px) {
  .gate-float { display: none; }
  .gate-hero-row img:not(.gate-hero) { display: none; }
  .header-title { max-width: 42vw; }
}
