:root {
  color-scheme: light dark;
  --green: #6fdc5f;
  --green-text: #23801a;
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --line: #dfe2e7;
  --text: #1b1d22;
  --text-dim: #5d6370;
  --code-bg: #f4f5f7;
  --bar: #c3c8d0;
  --bar-track: transparent;
  --side-w: 250px;
  --toc-w: 0px;
  --prose-w: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green-text: #7fe070;
    --bg: #1b1d22;
    --bg-soft: #22252b;
    --line: #33373f;
    --text: #e3e6eb;
    --text-dim: #9aa1ad;
    --code-bg: #24272e;
    --bar: #474c56;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--bar) var(--bar-track);
}

* { scrollbar-width: thin; scrollbar-color: var(--bar) var(--bar-track); }
*:hover { scrollbar-color: #8d939e var(--bar-track); }
pre:hover, .table-wrap:hover, .sidebar:hover, .toc:hover, .search-hits:hover { scrollbar-color: var(--green) var(--bar-track); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: var(--bar-track); }
::-webkit-scrollbar-thumb { background: var(--bar); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--green); background-clip: padding-box; }
pre::-webkit-scrollbar, .table-wrap::-webkit-scrollbar { height: 6px; }
pre::-webkit-scrollbar-thumb, .table-wrap::-webkit-scrollbar-thumb { border-width: 1px; }

body {
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, "Segoe UI", "Noto Sans", Ubuntu, Roboto, sans-serif;
}

a { color: var(--green-text); }
a:hover { text-decoration-thickness: 2px; }

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 55px;
  background: #1b1d22;
  border-bottom: 3px solid var(--green);
}

.top-in {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  height: 52px;
  margin: 0 auto;
  padding: 0 16px;
}

.brand {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
  white-space: nowrap;
}

.brand img { flex: none; }
.brand span { color: var(--green); font-weight: 400; }

.top-links { margin-left: auto; display: flex; flex: none; gap: 16px; }
.top-links a { color: #c9ced6; text-decoration: none; font-size: 14px; padding: 8px 0; }
.top-links a:hover { color: #fff; }

.nav-toggle, .search-open, .search-close {
  display: none;
  flex: none;
  background: none;
  border: 1px solid #4a4f59;
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  font-size: 14px;
  min-height: 40px;
  cursor: pointer;
}

.nav-toggle:hover, .search-open:hover, .search-close:hover { border-color: var(--green); }

.search {
  position: relative;
  flex: 0 1 340px;
  min-width: 0;
  margin-left: 20px;
}

.search-bar { position: relative; display: flex; align-items: center; gap: 8px; }

.search-input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 64px 0 12px;
  font: inherit;
  font-size: 14px;
  color: #fff;
  background: #2a2e35;
  border: 1px solid #4a4f59;
  border-radius: 6px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder { color: #9aa1ad; }
.search-input:focus { border-color: var(--green); background: #22252b; }
.search-input::-webkit-search-cancel-button { display: none; }

.search-key {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: #1b1d22;
  color: #9aa1ad;
  border-color: #4a4f59;
  pointer-events: none;
}

.search-input:focus + .search-key { display: none; }

.search-hits {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-top: 3px solid var(--green);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  padding: 4px;
}

.hit {
  position: relative;
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
  min-height: 44px;
}

.hit.on { background: var(--bg-soft); box-shadow: inset 3px 0 0 var(--green); }
.hit-title { display: block; font-weight: 600; font-size: 15px; padding-right: 56px; }
.hit-head { display: block; font-size: 14px; color: var(--green-text); }
.hit-text { display: block; font-size: 13px; color: var(--text-dim); overflow-wrap: anywhere; }
.hit-text.is-code { font-family: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.hit-lang { position: absolute; top: 10px; right: 10px; }
.hit mark { background: rgba(111, 220, 95, .4); color: inherit; border-radius: 2px; padding: 0 1px; }
.search-hits[hidden] { display: none; }
.search-none { margin: 0; padding: 12px 10px; color: var(--text-dim); font-size: 14px; }

.shade {
  position: fixed;
  top: 55px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 14;
  background: rgba(0, 0, 0, .45);
}

.shade[hidden] { display: none; }

.layout {
  display: flex;
  min-width: 0;
  margin: 0 auto;
}

.sidebar {
  flex: 0 0 var(--side-w);
  position: sticky;
  top: 55px;
  height: calc(100vh - 55px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 12px 40px 16px;
  border-right: 1px solid var(--line);
  font-size: 14px;
}

.sidebar h4 {
  margin: 18px 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
}

.sidebar h4:first-child { margin-top: 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }

.sidebar a {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
}

.sidebar a:hover { background: var(--bg-soft); }
.sidebar a.here { background: var(--green); color: #1b1d22; font-weight: 600; }

.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 24px 40px 40px;
}

.toc { display: none; }

.content h1[id], .content h2[id], .content h3[id] { scroll-margin-top: 72px; }

.content h1 { font-size: 32px; line-height: 1.25; margin: 4px 0 16px; }
.content h2 { font-size: 23px; margin: 38px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.content h3 { font-size: 18px; margin: 28px 0 8px; }
.content h3 code { font-size: 17px; }
.content h1, .content h2, .content h3, .content h4, .content p, .content li, .content td, .content th, .content dd, .content blockquote, .content a, .content :not(pre) > code { overflow-wrap: anywhere; }
.content > *, .content li > *, .content blockquote > * { max-width: 100%; }
.content > :is(p, ul, ol, dl, blockquote, h1, h2, h3, h4, hr) { max-width: var(--prose-w); }
.content div.highlighter-rouge, .content .highlight, .tabs, .table-wrap { min-width: 0; max-width: 100%; }
.content iframe, .content video, .content svg { max-width: 100%; }

.content img { max-width: 100%; height: auto; border-radius: 6px; }

code {
  font: 14px/1.5 ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 16px;
}

pre code { padding: 0; background: none; font-size: 13.5px; }

kbd {
  font: 500 11px/1 -apple-system, "Segoe UI", sans-serif;
  background: var(--bg-soft);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 5px 1px;
  vertical-align: middle;
  white-space: nowrap;
}

blockquote {
  margin: 0 0 16px;
  padding: 8px 14px;
  border-left: 4px solid var(--green);
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}

blockquote p { margin: 4px 0; }

table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 14px;
}

.table-wrap { max-width: 100%; overflow-x: auto; margin: 0 0 16px; }
.table-wrap table { display: table; overflow: visible; margin: 0; }

th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--bg-soft); }

hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }

.tabs { margin: 0 0 16px; }
.tabs pre { margin: 0; border-top-left-radius: 0; }
.tab-row { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tab-row::-webkit-scrollbar { display: none; }

.tab-row button {
  flex: none;
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
}

.tab-row button.on { background: var(--code-bg); color: var(--text); font-weight: 600; box-shadow: inset 0 2px 0 var(--green); }

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 48px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-dim);
}

.highlight .c, .highlight .c1, .highlight .cm, .highlight .cp, .highlight .cpf { color: #6a737d; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sc, .highlight .se { color: #0a7b35; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kr, .highlight .kc, .highlight .ow { color: #a626a4; }
.highlight .kt, .highlight .nc { color: #b35900; }
.highlight .m, .highlight .mi, .highlight .mh, .highlight .mf { color: #1d63c4; }
.highlight .nf, .highlight .fm { color: #3b5bdb; }

@media (prefers-color-scheme: dark) {
  .highlight .c, .highlight .c1, .highlight .cm, .highlight .cp, .highlight .cpf { color: #7d8590; }
  .highlight .s, .highlight .s1, .highlight .s2, .highlight .sc, .highlight .se { color: #8fdc7f; }
  .highlight .k, .highlight .kd, .highlight .kn, .highlight .kr, .highlight .kc, .highlight .ow { color: #d89cf6; }
  .highlight .kt, .highlight .nc { color: #f0b46a; }
  .highlight .m, .highlight .mi, .highlight .mh, .highlight .mf { color: #79b8ff; }
  .highlight .nf, .highlight .fm { color: #9db4ff; }
}

@media (min-width: 1024px) {
  .top-in { display: grid; grid-template-columns: 1fr auto 1fr; }
  .brand { justify-self: start; }
  .search { width: clamp(480px, 38vw, 640px); margin: 0; }
  .search-hits { width: 100%; }
  .top-links { justify-self: end; margin-left: 0; }
}

@media (min-width: 1800px) {
  .search { width: clamp(640px, 34vw, 760px); }
}

@media (min-width: 1280px) {
  :root { --toc-w: 240px; }
  .toc {
    display: block;
    flex: 0 0 var(--toc-w);
    position: sticky;
    top: 55px;
    height: calc(100vh - 55px);
    overflow-y: auto;
    padding: 28px 16px 40px 8px;
    font-size: 13px;
  }
  .toc-title {
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-dim);
  }
  .toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
  .toc a {
    display: block;
    padding: 3px 0 3px 12px;
    margin-left: -1px;
    border-left: 2px solid transparent;
    color: var(--text-dim);
    text-decoration: none;
    line-height: 1.4;
  }
  .toc .sub a { padding-left: 24px; }
  .toc a:hover { color: var(--text); }
  .toc a.here { color: var(--green-text); border-left-color: var(--green); }
}

@media (min-width: 1600px) {
  :root { --side-w: 280px; --toc-w: 260px; --prose-w: 1150px; }
  body { font-size: 17px; }
  .top-in { padding: 0 24px; }
  .sidebar { font-size: 15px; padding: 20px 14px 40px 24px; }
  .sidebar a { padding: 4px 10px; }
  .content { padding: 32px 56px 48px; }
  .content h1 { font-size: 36px; }
  .content h2 { font-size: 26px; }
  .content h3 { font-size: 20px; }
  code { font-size: 15px; }
  pre code { font-size: 14.5px; }
  .toc { font-size: 14px; padding-right: 24px; }
}

@media (min-width: 2200px) {
  :root { --side-w: 300px; --toc-w: 280px; --prose-w: 1200px; }
  body { font-size: 18px; }
  .sidebar { font-size: 16px; }
}

@media (min-width: 861px) and (max-width: 1100px) {
  :root { --side-w: 220px; }
  .content { padding: 24px 28px 40px; }
}

@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .top-links { display: none; }
  .search { flex: 1 1 auto; margin-left: auto; max-width: 360px; }
  .search-hits { left: auto; right: 0; }
  body.locked { overflow: hidden; }
  .sidebar {
    position: fixed;
    top: 55px;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    height: auto;
    z-index: 15;
    background: var(--bg);
    border-right: 1px solid var(--line);
    font-size: 16px;
    padding: 12px 12px 48px;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .2s ease, visibility 0s linear .2s;
  }
  .sidebar:not(.open) { overflow: hidden; }
  .sidebar.open { transform: none; visibility: visible; transition: transform .2s ease; }
  .sidebar h4 { margin-top: 20px; padding-left: 10px; }
  .sidebar a { display: block; padding: 10px 10px; min-height: 44px; }
  .sidebar kbd { margin-left: 4px; }
  .sidebar li { display: flex; align-items: center; }
  .sidebar li a { flex: 1; }
  .content { padding: 16px 16px 32px; }
  .content h1 { font-size: 26px; }
  .content h2 { font-size: 21px; }
  .tab-row button { min-height: 38px; padding: 6px 16px; }
  .foot a { padding: 8px 0; }
}

@media (max-width: 600px) {
  .search-open { display: flex; align-items: center; justify-content: center; margin-left: auto; width: 44px; padding: 0; }
  .search { display: none; }
  body.searching { overflow: hidden; }
  body.searching .search {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    max-width: none;
    margin: 0;
    background: var(--bg);
  }
  body.searching .search-bar {
    flex: none;
    height: 55px;
    padding: 0 12px;
    background: #1b1d22;
    border-bottom: 3px solid var(--green);
  }
  .search-input { height: 40px; font-size: 16px; padding-right: 12px; }
  .search-key { display: none; }
  body.searching .search-close { display: block; }
  .search-hits {
    position: static;
    flex: 1 1 auto;
    width: auto;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 4px 8px 24px;
  }
  .hit { padding: 12px 10px; border-bottom: 1px solid var(--line); border-radius: 0; }
  .hit-title { font-size: 16px; }
  .hit-head { font-size: 15px; }
  .hit-text { font-size: 14px; }
}

@media (max-width: 360px) {
  .top-in { gap: 8px; padding: 0 12px; }
  .brand { font-size: 17px; gap: 6px; }
  .nav-toggle { padding: 6px 10px; }
}

@media (max-width: 330px) {
  .brand span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar.open { transition: none; }
}

.demos { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; margin: 24px 0 32px; }
.demo { margin: 0; flex: 1 1 320px; min-width: 0; }
.demo-game { max-width: 420px; }
.demo-app { max-width: 600px; }
.demo iframe { display: block; width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #181a20; }
.demo-game iframe { height: 700px; }
.demo-app iframe { height: 640px; }
.demo figcaption { margin-top: 10px; font-size: 14px; color: var(--text-dim); }
.demo figcaption span { margin: 0 6px; }
