:root {
  --bg: #ffffff;
  --bg-alt: #f7f8fa;
  --bg-code: #f6f8fa;
  --text: #1c1e21;
  --text-muted: #5c6670;
  --border: #e6e8eb;
  --brand: #d94a3d;
  --brand-strong: #b8362b;
  --brand-soft: rgba(217, 74, 61, 0.10);
  --link: #c23c30;
  --shadow: 0 1px 2px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.06);
  --nav-h: 60px;
  --side: 264px;
  --toc: 220px;
  --content-max: 780px;

  --tok-comment: #6a737d;
  --tok-string: #1f883d;
  --tok-number: #0550ae;
  --tok-keyword: #cf222e;
  --tok-global: #8250df;
  --tok-func: #6639ba;
  --tok-section: #0550ae;
}
:root[data-theme="dark"] {
  --bg: #1b1b1d;
  --bg-alt: #212225;
  --bg-code: #17181a;
  --text: #e4e6e8;
  --text-muted: #a3a9b0;
  --border: #2c2e31;
  --brand: #f26b5e;
  --brand-strong: #ff8579;
  --brand-soft: rgba(242, 107, 94, 0.14);
  --link: #f58a7f;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.35);

  --tok-comment: #8b949e;
  --tok-string: #7ee787;
  --tok-number: #79c0ff;
  --tok-keyword: #ff7b72;
  --tok-global: #d2a8ff;
  --tok-func: #d2a8ff;
  --tok-section: #79c0ff;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 16px);
  font-size: clamp(15px, 0.35vw + 14.2px, 17px);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }

/* Navbar */
.navbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 clamp(14px, 3vw, 28px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.18rem; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.nav-spacer { flex: 1; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a { color: var(--text); font-weight: 500; font-size: 0.95rem; padding: 8px 12px; border-radius: 8px; }
.nav-links a:hover { background: var(--bg-alt); text-decoration: none; }
.nav-links a.gh { display: inline-flex; align-items: center; gap: 7px; }
.nav-links a.gh svg { width: 18px; height: 18px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 9px; flex: none;
  border: 1px solid var(--border); background: var(--bg-alt); color: var(--text); cursor: pointer;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.icon-btn svg { width: 18px; height: 18px; }
#menu-btn { display: none; }

/* Hero (landing) */
.hero {
  border-bottom: 1px solid var(--border);
  background: radial-gradient(1100px 400px at 78% -70%, var(--brand-soft), transparent 70%), var(--bg);
}
.hero-inner {
  width: min(1200px, 100%); margin: 0 auto;
  padding: clamp(48px, 7vw, 88px) clamp(20px, 4vw, 40px);
  display: grid; grid-template-columns: 1.05fr 1fr; gap: clamp(28px, 4vw, 52px); align-items: center;
}
.hero h1 { font-size: clamp(44px, 6.5vw, 70px); line-height: 1.02; margin: 0 0 8px; letter-spacing: -0.03em; font-weight: 800; }
.hero .tag { font-size: clamp(19px, 2.4vw, 24px); font-weight: 600; margin: 0 0 18px; letter-spacing: -0.01em; }
.hero p.sub { font-size: clamp(16px, 1.4vw, 18px); color: var(--text-muted); margin: 0 0 30px; max-width: 48ch; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 22px; border-radius: 10px; font-weight: 600; font-size: 1rem; cursor: pointer; border: 1px solid transparent; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-ghost { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }

/* Code window */
.window { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); background: var(--bg-code); }
.window-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg-alt); border-bottom: 1px solid var(--border); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.r { background: #ec6a5e; } .dot.y { background: #f4bf4f; } .dot.g { background: #61c554; }
.window-title { margin-left: 8px; font-size: 0.8rem; color: var(--text-muted); }
.window pre { margin: 0; }

/* Landing sections */
.landing { width: min(1120px, 100%); margin: 0 auto; padding: clamp(40px, 6vw, 72px) clamp(20px, 4vw, 40px); }
.landing h2 { text-align: center; font-size: clamp(26px, 3vw, 34px); letter-spacing: -0.02em; margin: 0 0 8px; }
.landing .lead { text-align: center; color: var(--text-muted); max-width: 60ch; margin: 0 auto 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.card { border: 1px solid var(--border); border-radius: 14px; padding: 22px; background: var(--bg-alt); }
.card .emoji { font-size: 24px; }
.card h3 { margin: 10px 0 8px; font-size: 1.05rem; }
.card p { margin: 0; font-size: 0.94rem; color: var(--text-muted); }
.center-cta { text-align: center; margin-top: 44px; }

/* Layout (docs) */
.backdrop { display: none; }
.layout {
  display: grid;
  grid-template-columns: var(--side) minmax(0, var(--content-max));
  justify-content: center;
  gap: clamp(28px, 3.4vw, 60px);
  width: 100%; margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 34px);
}
@media (min-width: 1280px) {
  .layout { grid-template-columns: var(--side) minmax(0, var(--content-max)) var(--toc); }
}

/* Sidebar */
.sidebar {
  position: sticky; top: var(--nav-h); align-self: start;
  height: calc(100vh - var(--nav-h));
  overflow-y: auto; padding: 26px 6px 60px;
  scrollbar-width: thin;
}
.side-search {
  display: flex; align-items: center; gap: 8px; margin: 0 6px 20px;
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; color: var(--text-muted);
}
.side-search svg { width: 15px; height: 15px; flex: none; }
.side-search input { border: none; background: transparent; outline: none; color: var(--text); font-size: 0.9rem; width: 100%; }
.side-search kbd { font-size: 11px; border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; background: var(--bg); color: var(--text-muted); }

.side-group { margin-bottom: 22px; }
.side-group-header { display: flex; align-items: center; gap: 9px; padding: 0 8px 9px; }
.side-group-header .gi { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.side-group-header .gi svg { width: 14px; height: 14px; }
.side-group-header h4 { margin: 0; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text); font-weight: 700; }
.side-items { display: flex; flex-direction: column; gap: 1px; margin-left: 12px; padding-left: 13px; border-left: 1px solid var(--border); }
.side-link { position: relative; display: block; padding: 6px 11px; border-radius: 7px; color: var(--text-muted); font-size: 0.9rem; font-weight: 500; transition: background .12s, color .12s; }
.side-link:hover { color: var(--text); background: var(--bg-alt); text-decoration: none; }
.side-link.active { color: var(--brand); background: var(--brand-soft); font-weight: 650; }
.side-link.active::before { content: ""; position: absolute; left: -14px; top: 7px; bottom: 7px; width: 2px; border-radius: 2px; background: var(--brand); }
.side-empty { padding: 8px 12px; color: var(--text-muted); font-size: 0.9rem; display: none; }

/* Content */
.content { padding: clamp(26px, 3vw, 42px) 2px 90px; min-width: 0; }
.doc-page { max-width: 100%; }
.content h1 { font-size: clamp(30px, 3.4vw, 40px); letter-spacing: -0.025em; margin: 0 0 6px; font-weight: 800; }
.content .eyebrow { color: var(--brand); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 10px; }
.content h2 { font-size: clamp(22px, 2.4vw, 28px); letter-spacing: -0.02em; margin: 40px 0 12px; font-weight: 750; }
.content h3 { font-size: 1.28rem; margin: 30px 0 10px; letter-spacing: -0.01em; }
.content h2 a.anchor, .content h3 a.anchor { opacity: 0; margin-left: 8px; color: var(--text-muted); font-weight: 400; }
.content h2:hover a.anchor, .content h3:hover a.anchor { opacity: 1; }
.content p { margin: 0 0 16px; }
.content ul, .content ol { margin: 0 0 16px; padding-left: 22px; }
.content li { margin: 5px 0; }
.content .lead { font-size: 1.12rem; color: var(--text-muted); }

:not(pre) > code { background: var(--brand-soft); color: var(--brand-strong); padding: 2px 6px; border-radius: 6px; font-size: 0.86em; }

.codeblock { position: relative; margin: 0 0 20px; }
.codeblock .window-title { font-size: 0.78rem; }
pre { margin: 0; padding: 16px 18px; overflow-x: auto; background: var(--bg-code); font-size: 0.84rem; line-height: 1.65; border-radius: 0 0 12px 12px; }
.codeblock > pre { border: 1px solid var(--border); border-radius: 12px; }
.codeblock.has-bar > pre { border-top: 0; border-radius: 0 0 12px 12px; }
.copy-btn { position: absolute; top: 8px; right: 8px; padding: 5px 10px; font-size: 0.72rem; border-radius: 7px; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; opacity: 0; transition: opacity .15s; }
.codeblock:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.copy-btn:hover { color: var(--brand); border-color: var(--brand); }

.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-string  { color: var(--tok-string); }
.tok-number  { color: var(--tok-number); }
.tok-keyword { color: var(--tok-keyword); }
.tok-global  { color: var(--tok-global); }
.tok-func    { color: var(--tok-func); }
.tok-section { color: var(--tok-section); }

.note { border: 1px solid var(--border); border-left: 4px solid var(--brand); background: var(--bg-alt); border-radius: 8px; padding: 12px 16px; margin: 0 0 20px; }
.note .note-title { font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--brand); margin-bottom: 4px; }
.note p:last-child { margin-bottom: 0; }

table { border-collapse: collapse; width: 100%; margin: 0 0 20px; font-size: 0.92rem; display: block; overflow-x: auto; }
th, td { text-align: left; padding: 9px 12px; border: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-alt); font-weight: 650; }
/* Keep code chips in tables on one line so short commands never split. */
td > code, th > code { white-space: nowrap; }

/* Pager */
.pager { display: flex; gap: 14px; margin-top: 48px; }
.pager a { flex: 1; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 3px; color: var(--text); }
.pager a:hover { border-color: var(--brand); text-decoration: none; }
.pager .dir { font-size: 0.78rem; color: var(--text-muted); }
.pager .pt { font-weight: 650; color: var(--brand); }
.pager a.next { text-align: right; align-items: flex-end; }
@media (max-width: 520px) { .pager { flex-direction: column; } }

/* Right TOC */
.toc { display: none; position: sticky; top: calc(var(--nav-h) + 22px); align-self: start; height: calc(100vh - var(--nav-h) - 44px); overflow-y: auto; padding-top: 4px; }
@media (min-width: 1280px) { .toc.has-items { display: block; } }
.toc h5 { margin: 0 0 10px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.toc a { display: block; padding: 4px 12px; color: var(--text-muted); border-left: 2px solid var(--border); font-size: 0.86rem; }
.toc a.lvl-3 { padding-left: 24px; }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--brand); border-left-color: var(--brand); }

footer { border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.9rem; padding: 30px 24px; text-align: center; }

/* Mobile drawer */
@media (max-width: 996px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  #menu-btn { display: inline-flex; }
  .nav-links a.docs { display: none; }
  .toc { display: none !important; }
  .sidebar {
    position: fixed; top: var(--nav-h); left: 0; z-index: 45;
    width: min(300px, 84vw); height: calc(100vh - var(--nav-h));
    background: var(--bg); border-right: 1px solid var(--border);
    transform: translateX(-103%); transition: transform .22s ease;
    padding: 22px 14px 60px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .backdrop.show { display: block; position: fixed; inset: var(--nav-h) 0 0 0; z-index: 44; background: rgba(0,0,0,0.45); }
}
@media (max-width: 720px) {
  .hero-inner { grid-template-columns: 1fr; }
  .hero-media { order: 2; }
}
