/* ── Theme tokens ──────────────────────────────────────────── */

:root,
[data-theme="light"] {
	--bg: #ffffff;
	--bg-secondary: #f6f8fa;
	--bg-tertiary: #eef1f4;
	--text: #1f2328;
	--text-secondary: #656d76;
	--text-tertiary: #8b949e;
	--border: #d0d7de;
	--border-light: #e4e8ec;
	--accent: #0969da;
	--accent-hover: #0550ae;
	--accent-subtle: #ddf4ff;
	--code-bg: #f0f3f6;
	--shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	--shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
	--sidebar-width: 280px;
	--header-height: 56px;
	--content-max-width: 820px;
}

[data-theme="dark"] {
	--bg: #0d1117;
	--bg-secondary: #161b22;
	--bg-tertiary: #1c2129;
	--text: #e6edf3;
	--text-secondary: #8b949e;
	--text-tertiary: #656d76;
	--border: #30363d;
	--border-light: #21262d;
	--accent: #58a6ff;
	--accent-hover: #79c0ff;
	--accent-subtle: #1a3a5c;
	--code-bg: #1c2129;
	--shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
	--shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ── Scrollbars ───────────────────────────────────────────── */

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

::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}

::-webkit-scrollbar-track {
	background: transparent;
}

::-webkit-scrollbar-thumb {
	background: var(--border);
	border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
	background: var(--text-tertiary);
}

/* ── Reset & base ─────────────────────────────────────────── */

*,
*::before,
*::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

html {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
	font-size: 16px;
	line-height: 1.6;
	color: var(--text);
	background: var(--bg);
	-webkit-text-size-adjust: 100%;
}

body {
	min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────── */

.site-header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 100;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: var(--header-height);
	padding: 0 16px;
	background: var(--bg);
	border-bottom: 1px solid var(--border);
}

.header-left,
.header-right {
	display: flex;
	align-items: center;
	gap: 12px;
}

.site-title {
	font-size: 1.1rem;
	font-weight: 600;
	color: var(--text);
	text-decoration: none;
}

.site-title:hover {
	color: var(--accent);
}

.site-subtitle {
	font-size: 0.85rem;
	color: var(--text-secondary);
}

/* ── Sidebar toggle (mobile) ─────────────────────────────── */

.sidebar-toggle {
	display: none;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border: none;
	border-radius: 6px;
	background: none;
	color: var(--text);
	cursor: pointer;
}

.sidebar-toggle:hover {
	background: var(--bg-secondary);
}

/* ── Theme toggle ─────────────────────────────────────────── */

.theme-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--bg);
	color: var(--text-secondary);
	cursor: pointer;
	transition: border-color 0.15s, color 0.15s;
}

.theme-toggle:hover {
	border-color: var(--accent);
	color: var(--accent);
}

[data-theme="light"] .icon-moon,
[data-theme="dark"] .icon-sun {
	display: none;
}

/* ── Language switcher (dropdown) ─────────────────────────── */

.lang-switcher {
	position: relative;
}

.lang-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--bg);
	font-size: 1.2rem;
	cursor: pointer;
	transition: border-color 0.15s;
}

.lang-toggle:hover {
	border-color: var(--accent);
}

.lang-dropdown {
	display: none;
	position: absolute;
	top: 100%;
	right: 0;
	margin-top: 4px;
	min-width: 160px;
	padding: 4px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--bg);
	box-shadow: var(--shadow-lg);
	z-index: 200;
}

.lang-dropdown[data-visible] {
	display: block;
}

.lang-option {
	display: block;
	padding: 6px 12px;
	border-radius: 4px;
	font-size: 0.875rem;
	text-decoration: none;
	color: var(--text);
	white-space: nowrap;
}

a.lang-option:hover {
	background: var(--bg-secondary);
}

.lang-option[data-current] {
	color: var(--accent);
	font-weight: 500;
}

.lang-flag {
	display: inline-block;
	vertical-align: middle;
}

/* ── Search ───────────────────────────────────────────────── */

.search-container {
	position: relative;
	width: 240px;
}

.search-container .pagefind-ui {
	--pagefind-ui-scale: 0.55;
	--pagefind-ui-primary: var(--accent);
	--pagefind-ui-text: var(--text);
	--pagefind-ui-background: var(--bg);
	--pagefind-ui-border: var(--border);
	--pagefind-ui-border-width: 1px;
	--pagefind-ui-border-radius: 6px;
	--pagefind-ui-font: inherit;
}

.search-container .pagefind-ui__search-input {
	font-weight: 400;
}

.search-container .pagefind-ui__search-clear {
	display: none;
}

.search-container .pagefind-ui__drawer {
	position: absolute;
	top: 100%;
	right: 0;
	width: max(400px, 100%);
	max-height: calc(100vh - var(--header-height) - 24px);
	overflow-y: auto;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 8px;
	box-shadow: var(--shadow-lg);
	padding: 0 12px 12px;
	z-index: 200;
}

.search-container .pagefind-ui__drawer:has(.pagefind-ui__results:empty):has(.pagefind-ui__message:empty) {
	display: none;
}

/* ── Layout ───────────────────────────────────────────────── */

.layout {
	display: flex;
	margin-top: var(--header-height);
	min-height: calc(100vh - var(--header-height));
}

/* ── Sidebar ──────────────────────────────────────────────── */

.sidebar {
	position: fixed;
	top: var(--header-height);
	left: 0;
	bottom: 0;
	width: var(--sidebar-width);
	overflow-y: auto;
	padding: 16px 0;
	border-right: 1px solid var(--border);
	background: var(--bg);
	z-index: 50;
}

.sidebar-backdrop {
	display: none;
}

/* ── Nav filter ───────────────────────────────────────────── */

.nav-filter {
	padding: 0 12px 12px;
}

.nav-filter input {
	width: 100%;
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--bg);
	color: var(--text);
	font-size: 0.85rem;
	outline: none;
	transition: border-color 0.15s;
}

.nav-filter input::placeholder {
	color: var(--text-tertiary);
}

.nav-filter input:focus {
	border-color: var(--accent);
}

/* ── Navigation ───────────────────────────────────────────── */

.nav-group {
	margin-bottom: 4px;
}

.nav-group-title {
	display: block;
	padding: 6px 12px;
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-tertiary);
	cursor: pointer;
	list-style: none;
	-webkit-user-select: none;
	user-select: none;
}

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

.nav-group-title::before {
	content: "▶ ";
	display: inline;
}

.nav-group[open] > .nav-group-title::before {
	content: "▼ ";
}

.nav-group-title:hover {
	color: var(--text-secondary);
}

.sidebar nav ul {
	list-style: none;
}

.sidebar nav a {
	display: block;
	padding: 6px 16px;
	font-size: 0.875rem;
	color: var(--text-secondary);
	text-decoration: none;
	border-left: 3px solid transparent;
	transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.sidebar nav a:hover {
	color: var(--text);
	background: var(--bg-secondary);
}

.sidebar nav a[aria-current="page"] {
	color: var(--accent);
	background: var(--accent-subtle);
	border-left-color: var(--accent);
	font-weight: 500;
}

/* ── Content area (main + TOC wrapper) ────────────────────── */

.content-area {
	display: flex;
	flex: 1;
	justify-content: center;
	margin-left: var(--sidebar-width);
	min-width: 0;
}

/* ── Main content ─────────────────────────────────────────── */

.content {
	flex: 1 1 0%;
	padding: 32px 40px 64px;
	max-width: var(--content-max-width);
	min-width: 0;
}

/* ── Table of contents (desktop — right column) ──────────── */

.toc {
	width: 220px;
	flex-shrink: 0;
	padding: 0 16px 24px 0;
}

@media (min-width: 1400px) {
	.toc {
		width: 300px;
	}
}

.toc-inner {
	position: sticky;
	top: calc(var(--header-height) + 24px);
	max-height: calc(100vh - var(--header-height) - 48px);
	overflow-y: auto;
	padding-left: 8px;
	border-left: 1px solid var(--border-light);
}

.toc-title {
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-tertiary);
	margin-bottom: 8px;
	padding-left: 8px;
}

.toc ul {
	list-style: none;
}

.toc li a {
	display: block;
	padding: 3px 8px;
	font-size: 0.8rem;
	line-height: 1.4;
	color: var(--text-secondary);
	text-decoration: none;
	border-left: 2px solid transparent;
	transition: color 0.15s, border-color 0.15s;
}

.toc li a:hover {
	color: var(--text);
}

.toc li[data-active] a {
	color: var(--accent);
	border-left-color: var(--accent);
}

.toc li.toc-sub a {
	padding-left: 18px;
	font-size: 0.75rem;
}

/* ── Table of contents (mobile — inline details) ─────────── */

.toc-mobile {
	display: none;
	margin-bottom: 24px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--bg-secondary);
}

.toc-mobile summary {
	padding: 10px 14px;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-secondary);
	cursor: pointer;
	list-style: none;
}

.toc-mobile summary::-webkit-details-marker {
	display: none;
}

.toc-mobile summary::before {
	content: "▸ ";
	display: inline;
}

.toc-mobile[open] summary::before {
	content: "▾ ";
}

.toc-mobile ul {
	list-style: none;
	padding: 0 14px 10px;
}

.toc-mobile li a {
	display: block;
	padding: 3px 0;
	font-size: 0.825rem;
	color: var(--text-secondary);
	text-decoration: none;
}

.toc-mobile li a:hover {
	color: var(--accent);
}

.toc-mobile li.toc-sub a {
	padding-left: 14px;
	font-size: 0.775rem;
}

/* ── Typography ───────────────────────────────────────────── */

.content h1 {
	font-size: 2rem;
	font-weight: 600;
	margin-bottom: 16px;
	padding-bottom: 8px;
	border-bottom: 1px solid var(--border);
}

.content h2 {
	font-size: 1.5rem;
	font-weight: 600;
	margin-top: 40px;
	margin-bottom: 12px;
	padding-bottom: 6px;
	border-bottom: 1px solid var(--border-light);
}

.content h3 {
	font-size: 1.2rem;
	font-weight: 600;
	margin-top: 32px;
	margin-bottom: 8px;
}

.content h4 {
	font-size: 1rem;
	font-weight: 600;
	margin-top: 24px;
	margin-bottom: 8px;
}

/* Heading anchor links */
.content h1[id],
.content h2[id],
.content h3[id],
.content h4[id],
.content h5[id],
.content h6[id] {
	position: relative;
	scroll-margin-top: calc(var(--header-height) + 16px);
}

.heading-anchor {
	color: var(--accent);
	font-weight: 400;
	text-decoration: none;
	opacity: 0;
	margin-left: 0.3em;
	transition: opacity 0.15s;
}

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

.content h1[id]:hover .heading-anchor,
.content h2[id]:hover .heading-anchor,
.content h3[id]:hover .heading-anchor,
.content h4[id]:hover .heading-anchor,
.content h5[id]:hover .heading-anchor,
.content h6[id]:hover .heading-anchor {
	opacity: 1;
}

.content p {
	margin-bottom: 16px;
}

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

.content a:hover {
	text-decoration: underline;
}

.content strong {
	font-weight: 600;
}

.content ul,
.content ol {
	margin-bottom: 16px;
	padding-left: 2em;
}

.content li {
	margin-bottom: 4px;
}

.content li > ul,
.content li > ol {
	margin-bottom: 0;
	margin-top: 4px;
}

.content hr {
	border: none;
	border-top: 1px solid var(--border);
	margin: 32px 0;
}

/* ── Inline code ──────────────────────────────────────────── */

.content code {
	padding: 2px 6px;
	border-radius: 4px;
	background: var(--code-bg);
	font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
	font-size: 0.875em;
}

/* ── Code blocks ──────────────────────────────────────────── */

.content pre {
	margin-bottom: 16px;
	padding: 16px;
	overflow-x: auto;
	border-radius: 8px;
	background: var(--code-bg);
	border: 1px solid var(--border-light);
}

.content pre code {
	padding: 0;
	background: none;
	border-radius: 0;
	font-size: 0.85rem;
	line-height: 1.5;
}

/* ── Blockquotes ──────────────────────────────────────────── */

.content blockquote {
	margin-bottom: 16px;
	padding: 12px 16px;
	border-left: 4px solid var(--accent);
	background: var(--bg-secondary);
	border-radius: 0 8px 8px 0;
	color: var(--text-secondary);
}

.content blockquote p:last-child {
	margin-bottom: 0;
}

/* ── Tables ───────────────────────────────────────────────── */

.content table {
	width: 100%;
	margin-bottom: 16px;
	border-collapse: collapse;
	font-size: 0.9rem;
}

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

.content th {
	background: var(--bg-secondary);
	font-weight: 600;
}

.content tr:nth-child(even) {
	background: var(--bg-secondary);
}

/* ── Images ───────────────────────────────────────────────── */

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

/* ── Back to top ──────────────────────────────────────────── */

.back-to-top {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 50;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--bg);
	color: var(--text-secondary);
	cursor: pointer;
	box-shadow: var(--shadow);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s, border-color 0.15s, color 0.15s;
}

.back-to-top[data-visible] {
	opacity: 1;
	pointer-events: auto;
}

.back-to-top:hover {
	border-color: var(--accent);
	color: var(--accent);
}

/* ── Mobile search overlay ───────────────────────────────── */

.search-toggle {
	display: none;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--bg);
	color: var(--text-secondary);
	cursor: pointer;
	transition: border-color 0.15s, color 0.15s;
}

.search-toggle:hover {
	border-color: var(--accent);
	color: var(--accent);
}

.search-overlay {
	display: none;
	position: fixed;
	inset: 0;
	top: var(--header-height);
	z-index: 150;
	background: var(--bg);
	padding: 16px;
	overflow-y: auto;
}

.search-overlay[data-visible] {
	display: block;
}

.search-overlay .pagefind-ui {
	--pagefind-ui-scale: 0.7;
	--pagefind-ui-primary: var(--accent);
	--pagefind-ui-text: var(--text);
	--pagefind-ui-background: var(--bg);
	--pagefind-ui-border: var(--border);
	--pagefind-ui-border-width: 1px;
	--pagefind-ui-border-radius: 6px;
	--pagefind-ui-font: inherit;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 1100px) {
	.toc {
		display: none;
	}

	.toc-mobile {
		display: block;
	}
}

@media (max-width: 768px) {
	.sidebar-toggle {
		display: flex;
	}

	.site-subtitle {
		display: none;
	}

	.sidebar {
		transform: translateX(-100%);
		transition: transform 0.25s ease;
		box-shadow: none;
	}

	.sidebar[data-visible] {
		transform: translateX(0);
		box-shadow: var(--shadow-lg);
	}

	.sidebar-backdrop[data-visible] {
		display: block;
		position: fixed;
		inset: 0;
		top: var(--header-height);
		z-index: 40;
		background: rgba(0, 0, 0, 0.3);
	}

	.content-area {
		margin-left: 0;
	}

	.content {
		padding: 24px 16px 48px;
	}
}

@media (max-width: 768px) {
	.search-container {
		width: 160px;
	}

	.search-container .pagefind-ui__drawer {
		position: fixed;
		top: var(--header-height);
		left: 0;
		right: 0;
		width: auto;
		border-radius: 0;
		border-top: none;
	}
}

@media (max-width: 480px) {
	.search-container {
		display: none;
	}

	.search-toggle {
		display: flex;
	}
}
