/* GitBook clone — Web3sb (theme-muted, circular-corners, sidebar-filled, sidebar-list-pill) */
:root {
  color-scheme: dark;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --header-h: 64px;
  --sidebar-w: 288px;
  --aside-w: 256px;
  --radius-pill: 999px;
  --radius-xl: 16px;
  --radius-3xl: 24px;
  /* GitBook dark tint scale */
  --bg: #232222;
  --surface: #2d2b2b;
  --surface-subtle: #353030;
  --surface-filled: #353030;
  --hover: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.06);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --text: #fffffe;
  --muted: #91807e;
  --faint: #9d8c8a;
  --tint-strong: #c0bebd;
  --primary: #db3434;
  --primary-hover: #f34d49;
  --primary-soft: #352827;
  --primary-subtle: rgba(219, 52, 52, 0.12);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
}

html.light {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #fbfbfc;
  --surface-subtle: #f3f4f6;
  --surface-filled: #f3f4f6;
  --hover: rgba(0, 0, 0, 0.04);
  --border: rgba(0, 0, 0, 0.08);
  --border-subtle: rgba(0, 0, 0, 0.05);
  --text: #1d1d1d;
  --muted: #787878;
  --faint: #909090;
  --tint-strong: #484848;
  --primary: #db3434;
  --primary-hover: #c42e2e;
  --primary-soft: rgba(219, 52, 52, 0.1);
  --primary-subtle: rgba(219, 52, 52, 0.08);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html {
  font-family: var(--font);
  scroll-behavior: smooth;
}

html.os-mac .win-only { display: none; }
html:not(.os-mac) .mac-only { display: none; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.625;
  -webkit-font-smoothing: antialiased;
}

body.ai-open { overflow: hidden; }

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; border: 0; background: none; color: inherit; }

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

/* ── Header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1536px;
  height: 100%;
  margin: 0 auto;
  padding: 0 max(env(safe-area-inset-right), 24px) 0 max(env(safe-area-inset-left), 24px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  width: var(--sidebar-w);
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  min-width: 0;
}

.header-logo img {
  max-height: 32px;
  max-width: 160px;
  object-fit: contain;
  object-position: left;
  border-radius: 6px;
}

html.dark .logo-light { display: none; }
html.light .logo-dark { display: none; }

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.top-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(100%, 480px);
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-3xl);
  background: var(--bg);
  color: var(--muted);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.top-search:focus-within {
  border-color: var(--primary-hover);
  box-shadow: 0 0 0 2px var(--primary-subtle), var(--shadow-md);
  transform: translateY(-1px);
}

.top-search svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  flex-shrink: 0;
}

.top-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.top-search input::placeholder { color: color-mix(in srgb, var(--muted) 50%, transparent); }

.shortcut {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-family: inherit;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.ask-ai-switcher { position: relative; }

.ask-ai-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 40%, var(--border));
  border-radius: var(--radius-3xl);
  background: var(--primary-subtle);
  color: var(--primary-hover);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ask-ai-header-btn:hover,
.ask-ai-switcher.open .ask-ai-header-btn {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-subtle) 60%, var(--surface-subtle));
  color: var(--text);
}

.ask-ai-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.ask-ai-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 220px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.ask-ai-menu.hidden { display: none; }

.ask-ai-menu button {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
  color: var(--text);
  transition: background 0.12s;
}

.ask-ai-menu button:hover {
  background: var(--hover);
}

.ask-ai-switcher.open .lang-chevron { transform: rotate(180deg); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xl);
  color: var(--tint-strong);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ── Language ── */
.lang-switcher { position: relative; }

.lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-3xl);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s;
}

.lang-trigger:hover,
.lang-switcher.open .lang-trigger {
  background: var(--hover);
}

.lang-chevron {
  width: 10px;
  height: 10px;
  fill: var(--muted);
  transition: transform 0.15s;
}

.lang-switcher.open .lang-chevron { transform: rotate(180deg); }

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 150px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.lang-menu.hidden { display: none; }

.lang-menu button {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  color: var(--text);
  transition: background 0.12s;
}

.lang-menu button:hover { background: var(--hover); }

.lang-menu button.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--aside-w);
  max-width: 1536px;
  margin: 0 auto;
  min-height: calc(100dvh - var(--header-h));
}

/* ── Sidebar (filled) ── */
.sidebar {
  position: sticky;
  top: var(--header-h);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h));
  background: var(--surface-filled);
  overflow: hidden;
}

.sidebar-mobile-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo img { max-height: 28px; }

.mobile-lang { height: 32px; padding: 0 10px; font-size: 13px; }

.nav-tree {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
}

.section { margin-bottom: 2px; }

.section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--tint-strong);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.section-toggle:hover {
  background: var(--hover);
  color: var(--text);
}

.section-toggle svg {
  width: 10px;
  height: 10px;
  fill: currentColor;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.section.open .section-toggle svg { transform: rotate(90deg); }

.section-pages {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.2s ease;
  padding-left: 4px;
}

.section.open .section-pages { max-height: 900px; }

.nav-link {
  display: block;
  margin: 2px 0;
  padding: 6px 6px 6px 12px;
  border-radius: var(--radius-xl);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  transition: background 0.12s, color 0.12s;
}

.nav-link:hover {
  background: var(--hover);
  color: var(--text);
}

.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 500;
}

.sidebar-foot {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--border-subtle);
}

.theme-row {
  display: flex;
  gap: 6px;
}

.theme-chip {
  flex: 1;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.theme-chip:hover { background: var(--hover); color: var(--text); }

.theme-chip.active {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}

.powered-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px;
  border-radius: 10px;
  color: var(--faint);
  font-size: 12px;
  transition: color 0.12s;
}

.powered-by svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.powered-by:hover { color: var(--primary); }

/* ── Main content ── */
.page-main {
  min-width: 0;
  padding: 32px 48px 80px;
}

.page-article {
  width: min(100%, 768px);
  margin: 0 auto;
}

.page-meta {
  margin-bottom: 12px;
}

.page-meta a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.12s;
}

.page-meta a:hover { color: var(--primary); }

.article-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 32px;
}

.page-article h1 {
  margin: 0;
  font-size: 36px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  overflow-wrap: anywhere;
}

.ask-ai-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--primary) 48%, var(--border));
  border-radius: var(--radius-3xl);
  background: var(--primary-subtle);
  color: var(--primary-hover);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.ask-ai-btn:hover,
.ask-ai-btn:focus-visible {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-subtle) 55%, var(--surface-subtle));
  color: var(--text);
  transform: translateY(-1px);
}

.page-body {
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
}

.page-body p { margin: 0 0 1.25em; }

.page-body h2 {
  margin: 2em 0 0.75em;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-body h2:first-child { margin-top: 0; }

.page-body ul, .page-body ol {
  margin: 0 0 1.25em;
  padding-left: 1.5em;
}

.page-body li { margin-bottom: 0.35em; }

.page-body table {
  width: 100%;
  margin: 0 0 1.5em;
  border-collapse: collapse;
  font-size: 14px;
}

.page-body th, .page-body td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
}

.page-body th {
  background: var(--surface-subtle);
  font-weight: 600;
}

.page-body code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875em;
}

.page-body blockquote {
  margin: 0 0 1.25em;
  padding: 12px 16px;
  border-left: 3px solid var(--primary);
  background: var(--primary-subtle);
  color: var(--muted);
  border-radius: 0 10px 10px 0;
}

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

.page-body a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.page-body a:hover { color: var(--primary-hover); }

.page-body strong { font-weight: 600; }

.page-body .mark-success {
  color: var(--success, #22c55e);
  font-weight: 600;
}

.page-body pre {
  margin: 0 0 1.25em;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-subtle);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

.page-body pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.page-body h3 {
  margin: 1.5em 0 0.5em;
  font-size: 1.125rem;
  font-weight: 600;
}

.doc-figure {
  margin: 0 0 1.5em;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--surface-subtle);
}

.doc-figure img {
  display: block;
  width: 100%;
  height: auto;
}

.doc-figure figcaption {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  border-top: 1px solid var(--border-subtle);
}

.updated {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
  color: var(--faint);
  font-size: 13px;
}

.page-nav {
  width: min(100%, 768px);
  margin: 2rem auto 0;
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--muted);
  font-size: 13px;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.page-link:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--text);
  transform: translateY(-1px);
}

.page-link-label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  text-transform: capitalize;
}

.page-link strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.page-link svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  flex-shrink: 0;
}

/* ── Right aside ── */
.page-aside {
  border-left: 1px solid var(--border-subtle);
}

.aside-inner {
  position: sticky;
  top: var(--header-h);
  padding: 32px 20px 24px 24px;
  max-height: calc(100dvh - var(--header-h));
  overflow-y: auto;
}

.aside-label {
  margin: 0 0 12px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}

.on-page a {
  display: block;
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  transition: border-color 0.12s, color 0.12s;
}

.on-page a:hover,
.on-page a.active {
  border-left-color: var(--primary);
  color: var(--text);
}

.only-mobile { display: none; }

.mobile-scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.5);
}

.mobile-scrim[hidden] { display: none; }

/* ── Mistral AI panel ── */
.ai-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  place-items: center;
  padding: 24px;
}

.ai-modal[aria-hidden="false"] { display: grid; }

.ai-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
}

.ai-panel {
  position: relative;
  width: min(100%, 680px);
  max-height: min(760px, calc(100dvh - 48px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: color-mix(in srgb, var(--bg) 92%, var(--surface-subtle));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.ai-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.ai-kicker {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ai-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.ai-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.ai-close:hover { background: var(--hover); color: var(--text); }

.ai-context {
  margin: 16px 22px 0;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.ai-form {
  display: grid;
  gap: 10px;
  padding: 16px 22px 0;
}

.ai-input-label {
  color: var(--tint-strong);
  font-size: 13px;
  font-weight: 600;
}

.ai-form textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.ai-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.ai-submit {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-3xl);
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.ai-submit:hover { background: var(--primary-hover); }
.ai-submit:disabled { cursor: wait; opacity: 0.68; }

.ai-submit svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.ai-answer {
  margin: 18px 22px 22px;
  min-height: 88px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.ai-answer p {
  margin: 0 0 0.9em;
}

.ai-answer p:last-child {
  margin-bottom: 0;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .page-aside { display: none; }
}

@media (max-width: 768px) {
  .header-left {
    width: auto;
    padding-left: 0;
  }

  .header-inner {
    padding: 0 12px;
    gap: 8px;
  }

  .header-center { flex: 0; }

  .top-search {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .top-search input,
  .top-search .shortcut { display: none; }

  .top-search:focus-within {
    position: absolute;
    right: 120px;
    width: 220px;
    padding: 0 12px;
  }

  .top-search:focus-within input { display: block; }

  .only-mobile { display: flex; }

  .layout { display: block; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 45;
    width: min(300px, 88vw);
    height: 100dvh;
    top: 0;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-md);
  }

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

  .sidebar-mobile-head { display: flex; }

  .page-main { padding: 24px 16px 60px; }

  .article-title-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .ask-ai-btn {
    align-self: flex-start;
  }

  .ai-modal {
    align-items: end;
    padding: 12px;
  }

  .ai-panel {
    width: 100%;
    max-height: calc(100dvh - 24px);
    border-radius: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
