* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: calc(19px * var(--font-scale));
  line-height: 1.75;
  letter-spacing: 0.005em;
  transition:
    background var(--transition),
    color var(--transition),
    font-size var(--transition);
  min-height: 100vh;
}

::selection {
  background: rgba(var(--particle), 0.35);
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

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

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
  color: var(--heading);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

strong,
b {
  font-weight: 700;
}

h1 {
  font-size: 2.4rem;
  margin: 0 0 0.6em;
}
h1#ptgb,
h1#ptgc,
h1#penv {
  font-family: var(--font-mono);
}
h2 {
  font-size: 1.7rem;
  margin: 1.8em 0 0.6em;
  padding-top: 0.3em;
  border-top: 1px solid var(--border);
}
h2:first-of-type {
  border-top: none;
  padding-top: 0;
}
h3 {
  font-size: 1.32rem;
  margin: 1.6em 0 0.5em;
}
h3 code {
  font-size: 0.85em;
}
p {
  margin: 0 0 1.1em;
}
ul,
ol {
  margin: 0 0 1.1em;
  padding-left: 1.4em;
}
li {
  margin-bottom: 0.35em;
}

blockquote {
  margin: 1.2em 0;
  padding: 0.2em 1.2em;
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 0.92em;
}
th,
td {
  text-align: left;
  padding: 0.55em 0.8em;
  border: 1px solid var(--border);
}
th {
  background: var(--bg-elevated);
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--heading);
}
tr:nth-child(even) td {
  background: rgba(var(--particle), 0.035);
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 0.12em 0.4em;
  color: var(--accent-2);
}

.highlight,
pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 1.1em 1.3em;
  overflow-x: auto;
  margin: 1.3em 0;
  box-shadow: var(--shadow);
}
.highlight pre {
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  background: transparent;
}
pre,
code {
  font-variant-ligatures: none;
}
pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 0.92em;
}
.highlight,
.highlight pre,
pre {
  font-family: var(--font-mono);
  line-height: 1.6;
}

.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kt,
.highlight .kr {
  color: var(--tok-keyword);
  font-weight: 600;
}
.highlight .s,
.highlight .s1,
.highlight .s2,
.highlight .sa,
.highlight .dl {
  color: var(--tok-string);
}
.highlight .c,
.highlight .c1,
.highlight .cm,
.highlight .cs {
  color: var(--tok-comment);
  font-style: italic;
}
.highlight .mi,
.highlight .mf,
.highlight .m {
  color: var(--tok-number);
}
.highlight .nf,
.highlight .fm {
  color: var(--tok-function);
}
.highlight .nc,
.highlight .nn {
  color: var(--tok-class);
}
.highlight .o,
.highlight .p {
  color: var(--tok-operator);
}
.highlight .nb,
.highlight .bp {
  color: var(--tok-function);
}
.highlight .n {
  color: var(--text);
}

.code-copy {
  position: absolute;
  top: 0.6em;
  right: 0.6em;
  font-family: var(--font-body);
  font-size: 0.75rem;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.25em 0.7em;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition);
}
.highlight:hover .code-copy,
pre:hover .code-copy {
  opacity: 1;
}
.code-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
}

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
}
[data-theme="dark"] #bg-canvas {
  opacity: 0.4;
}

.shell {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.9em;
  padding: 0 1.2em;
  background: rgba(var(--particle), 0.07);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.55em;
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--heading);
}
.topbar .brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.topbar .brand .name {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0;
}
.topbar .spacer {
  flex: 1;
}
.topbar .tagline {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.95rem;
  display: none;
}
@media (min-width: 900px) {
  .topbar .tagline {
    display: inline;
  }
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition:
    border-color var(--transition),
    color var(--transition),
    background var(--transition);
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

.gh-link {
  display: inline-flex;
}

/* Native <select> is kept in the DOM for no-JS / form fallback, but visually hidden
   once the custom dropdown takes over. */
.version-switch {
  position: relative;
}
.version-switch select.vs-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}
.version-switch.no-js select.vs-native {
  position: static;
  opacity: 1;
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  height: 38px;
  padding: 0 2.1em 0 0.9em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a8987a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65em center;
  background-size: 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  cursor: pointer;
}

.vs-btn {
  display: none;
  align-items: center;
  gap: 0.6em;
  height: 38px;
  padding: 0 2.1em 0 0.9em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  cursor: pointer;
  position: relative;
  transition:
    border-color var(--transition),
    color var(--transition),
    background-color var(--transition),
    box-shadow var(--transition);
}
.version-switch.js .vs-btn {
  display: inline-flex;
}
.vs-btn::after {
  content: "";
  position: absolute;
  right: 0.65em;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a8987a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
    no-repeat center / contain;
  transition: transform var(--dur-med, 200ms) var(--ease, ease);
}
.vs-btn:hover,
.vs-btn[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.vs-btn[aria-expanded="true"]::after {
  transform: translateY(-50%) rotate(180deg);
}
.vs-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.vs-list {
  list-style: none;
  margin: 0;
  padding: 0.35em;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow), var(--shadow-glow);
  z-index: 50;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition:
    opacity var(--dur-med, 200ms) var(--ease, ease),
    transform var(--dur-med, 200ms) var(--ease, ease);
}
.vs-list[data-open="true"] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.vs-option {
  padding: 0.5em 0.8em;
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background var(--transition),
    color var(--transition);
}
.vs-option:hover,
.vs-option.is-active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}
.vs-option[aria-selected="true"]::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.55em;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.vs-option:not([aria-selected="true"])::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.55em;
  vertical-align: middle;
}

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

.font-size-control {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-elevated);
}
.font-size-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
  line-height: 1;
  padding: 0 0.55em;
  transition:
    background var(--transition),
    color var(--transition);
}
.font-size-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}
.font-size-btn[data-size="small"] {
  font-size: 12px;
}
.font-size-btn[data-size="medium"] {
  font-size: 15px;
}
.font-size-btn[data-size="large"] {
  font-size: 18px;
}
.font-size-btn:hover {
  color: var(--accent);
}
.font-size-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
}
.font-size-btn[aria-pressed="true"]:hover {
  color: var(--bg);
}

.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.2em 0.9em 3em;
  z-index: 30;
  transition:
    transform var(--transition),
    width var(--transition);
}
body.sidebar-collapsed .sidebar {
  transform: translateX(calc(-1 * var(--sidebar-w)));
}

.sidebar input.nav-search {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.55em 0.8em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 1em;
}
.sidebar input.nav-search:focus {
  outline: none;
  border-color: var(--accent);
}

.nav-section {
  margin-bottom: 0.3em;
}
.nav-section-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5em;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.65em 0.5em;
  border-radius: 6px;
  text-align: left;
}
.nav-section-btn:hover {
  color: var(--accent);
  background: rgba(var(--particle), 0.06);
}
.nav-section-btn .chev {
  margin-left: auto;
  transition: transform var(--transition);
  font-size: 0.85em;
}
.nav-section.collapsed .chev {
  transform: rotate(-90deg);
}
.nav-section.collapsed .nav-list {
  display: none;
}

.nav-list {
  list-style: none;
  margin: 0.2em 0 0.6em;
  padding-left: 0.6em;
  border-left: 1px solid var(--border);
}
.nav-list li {
  margin: 0;
}
.nav-list a {
  display: block;
  padding: 0.42em 0.7em;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.98rem;
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
}
.nav-list a:hover {
  background: rgba(var(--particle), 0.08);
  color: var(--accent);
}
.nav-list a.active {
  color: var(--accent-strong);
  font-weight: 600;
  border-left-color: var(--accent);
  background: rgba(var(--particle), 0.1);
}

.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding-top: var(--header-h);
  transition: margin-left var(--transition);
  min-width: 0;
}
body.sidebar-collapsed .main-wrap {
  margin-left: 0;
}

.content {
  max-width: var(--max-content-w);
  margin: 0 auto;
  padding: 2.6em 2em 6em;
  transition: max-width var(--transition);
}
body.sidebar-collapsed .content {
  max-width: calc(var(--max-content-w) + var(--sidebar-w));
}

.breadcrumb {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.4em;
}
.breadcrumb a {
  color: var(--text-muted);
}
.breadcrumb a:hover {
  color: var(--accent);
}
.breadcrumb a[aria-current="page"] {
  color: var(--text);
  pointer-events: none;
}
.breadcrumb a.breadcrumb-static {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1em;
  margin: 1.6em 0 2em;
}
@media (max-width: 640px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}
.card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1em 1.3em;
  box-shadow: var(--shadow);
  transition:
    transform var(--transition),
    border-color var(--transition);
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  text-decoration: none;
}
.card h3 {
  margin: 0 0 0.3em;
  font-size: 1.08rem;
}
.card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  margin-top: 3em;
  padding-top: 1.4em;
  border-top: 1px solid var(--border);
}
.page-nav a {
  flex: 1;
  max-width: 48%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8em 1.1em;
  color: var(--text);
  text-decoration: none;
}
.page-nav a:hover {
  border-color: var(--accent);
}
.page-nav .dir {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.2em;
}
.page-nav .next {
  text-align: right;
  margin-left: auto;
}

footer.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.6em 2em 3em;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: var(--max-content-w);
  margin: 0 auto;
}
footer.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

.mobile-toggle {
  display: none;
}
@media (max-width: 980px) {
  .mobile-toggle {
    display: inline-flex;
  }
  #sidebar-collapse-toggle {
    display: none;
  }
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
    box-shadow: none;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }
  .main-wrap {
    margin-left: 0 !important;
  }
  .scrim {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-h);
    background: rgba(0, 0, 0, 0.35);
    z-index: 20;
  }
  body.sidebar-open .scrim {
    display: block;
  }
  .content {
    padding: 2em 1.2em 4em;
  }
  h1 {
    font-size: 1.95rem;
  }
  body {
    font-size: calc(18px * var(--font-scale));
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 0 0.7em;
    gap: 0.5em;
  }
  .topbar .brand span.name {
    display: none;
  }
}
