/* Every-Embodied static docs site */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --sidebar-bg: #fbfbfc;
  --text: #1f2328;
  --text-soft: #424a53;
  --muted: #7a828c;
  --border: #e4e7eb;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.09);
  --code-bg: #eff1f3;
  --pre-bg: #f6f8fa;
  --mark-bg: #fff3ad;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
  --topbar-h: 56px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-soft: #1a2028;
  --sidebar-bg: #12171d;
  --text: #e6e8eb;
  --text-soft: #c4cad1;
  --muted: #8b949e;
  --border: #2a3138;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --code-bg: #242b33;
  --pre-bg: #161c22;
  --mark-bg: #5c5014;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

kbd {
  font-family: inherit;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--bg);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
}

.skip-link:focus {
  left: 8px;
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-soft);
  text-decoration: none;
}

#menu-btn {
  display: none;
}

#theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] #theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] #theme-toggle .icon-moon {
  display: none;
}

.lang-btn {
  width: auto;
  padding: 0 11px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 700;
  min-width: 0;
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  border-radius: 50%;
  flex: none;
}

.brand-name {
  font-size: 16px;
  letter-spacing: 0.2px;
}

.brand-tag {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}

.search {
  position: relative;
  margin-left: auto;
  width: min(260px, 36vw);
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 34px;
  padding: 0 38px 0 32px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search kbd {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(420px, 92vw);
  max-height: min(480px, 70vh);
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.search-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
}

.search-item:hover,
.search-item.active {
  background: var(--accent-soft);
  text-decoration: none;
}

.search-item-group {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 1px;
}

.search-item-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.search-item-snippet {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 2px;
}

.search-panel mark {
  background: var(--mark-bg);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.search-empty {
  padding: 14px 12px;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 14px 12px 32px;
}

.sidebar-backdrop {
  display: none;
}

.nav-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  padding: 8px 10px;
  margin: 2px 0;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

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

.nav-group summary::before {
  content: "▸";
  flex: none;
  color: var(--muted);
  font-size: 11px;
  transition: transform 0.15s;
}

.nav-group[open] summary::before {
  transform: rotate(90deg);
}

.nav-group summary:hover {
  background: var(--bg-soft);
}

.nav-group-title {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
}

.nav-group-count {
  flex: none;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 0 7px;
}

.nav-group ul {
  list-style: none;
  margin: 0 0 6px;
  padding: 0 0 0 8px;
}

.sidebar-nav li a {
  display: block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-soft);
  word-break: break-word;
}

.sidebar-nav li a:hover {
  background: var(--bg-soft);
  color: var(--text);
  text-decoration: none;
}

.sidebar-nav li a.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-nav li .nav-plain {
  display: block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-soft);
  word-break: break-word;
}

/* ---------- content ---------- */

.content {
  padding: 30px clamp(18px, 4vw, 44px) 48px;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

.doc-meta {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 10px;
}

.doc {
  line-height: 1.8;
  color: var(--text);
  word-wrap: break-word;
}

.doc h1,
.doc h2,
.doc h3,
.doc h4 {
  font-weight: 700;
  line-height: 1.4;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.doc h1 {
  font-size: 1.85em;
  margin: 0.5em 0 0.8em;
}

.doc h2 {
  font-size: 1.42em;
  margin: 1.8em 0 0.7em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
}

.doc h3 {
  font-size: 1.18em;
  margin: 1.5em 0 0.6em;
}

.doc h4 {
  font-size: 1.04em;
  margin: 1.3em 0 0.5em;
}

.doc .doc-heading {
  position: relative;
}

.doc .doc-heading .anchor {
  position: absolute;
  left: -0.85em;
  color: var(--muted);
  opacity: 0;
  font-weight: 400;
}

.doc .doc-heading:hover .anchor {
  opacity: 1;
  text-decoration: none;
}

.doc p {
  margin: 0.85em 0;
}

.doc li {
  margin: 0.3em 0;
}

.doc img,
.doc video {
  max-width: 100%;
  border-radius: 10px;
}

.doc p > img:only-child,
.doc p > video:only-child {
  display: block;
  margin: 14px auto;
  box-shadow: 0 2px 16px rgba(15, 23, 42, 0.08);
}

.doc blockquote {
  margin: 1em 0;
  padding: 10px 18px;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--accent-soft);
  color: var(--text-soft);
}

.doc blockquote p {
  margin: 0.4em 0;
}

.doc code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: 0.86em;
  background: var(--code-bg);
  border-radius: 5px;
  padding: 2px 6px;
}

.doc pre {
  position: relative;
  background: var(--pre-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.6;
  font-size: 13.5px;
}

.doc pre code {
  display: block;
  background: transparent;
  padding: 0;
  font-size: inherit;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 12px;
  font-family: inherit;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.doc pre:hover .code-copy,
.code-copy:focus-visible {
  opacity: 1;
}

.code-copy:hover {
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  margin: 1em 0;
}

.doc table {
  border-collapse: collapse;
  font-size: 14px;
  min-width: 50%;
}

.doc th,
.doc td {
  border: 1px solid var(--border);
  padding: 7px 13px;
  text-align: left;
}

.doc th {
  background: var(--bg-soft);
  font-weight: 600;
}

.doc hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.doc .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

.disabled-link {
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- code language badge & chapter select ---------- */

.code-lang {
  position: absolute;
  top: 7px;
  left: 14px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color: var(--muted);
  pointer-events: none;
  user-select: none;
}

.doc pre:has(> .code-lang) {
  padding-top: 34px;
}

.chapter-select {
  height: 34px;
  max-width: 230px;
  padding: 0 8px 0 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
}

.chapter-select:focus {
  border-color: var(--accent);
}

.chapter-select:hover {
  border-color: var(--muted);
}

@media (max-width: 900px) {
  .chapter-select {
    display: none;
  }
}

/* ---------- pager / footer ---------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 52px;
  padding-top: 26px;
  border-top: 1px solid var(--border);
}

.pager-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pager-item:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: 0 2px 12px var(--accent-soft);
}

.pager-next {
  text-align: right;
  align-items: flex-end;
}

.pager-label {
  font-size: 12px;
  color: var(--muted);
}

.pager-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
}

.back-top {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 60;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
  transition: transform 0.15s;
}

.back-top:hover {
  transform: translateY(-2px);
}

.footer {
  padding: 26px 16px 34px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

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

.notfound-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--bg-soft);
}

.notfound {
  text-align: center;
  padding: 32px;
}

.notfound-code {
  font-size: 72px;
  font-weight: 800;
  color: var(--accent);
  margin: 0;
  line-height: 1;
}

.notfound .button {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 22px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.notfound .button:hover {
  text-decoration: none;
  opacity: 0.9;
}

/* ---------- mobile ---------- */

@media (max-width: 1023px) {
  #menu-btn {
    display: inline-flex;
  }

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

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 70;
    height: 100vh;
    width: min(320px, 84vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    padding-top: 18px;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(15, 23, 42, 0.45);
  }

  .brand-tag {
    display: none;
  }

  .content {
    padding-top: 22px;
  }
}

@media (max-width: 560px) {
  .search {
    width: min(190px, 42vw);
  }

  .search kbd {
    display: none;
  }

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

  .pager-next {
    text-align: left;
    align-items: flex-start;
  }

  .back-top {
    right: 16px;
    bottom: 16px;
  }
}
