body {
	margin: 0;
	background: var(--color-bg);
	color: var(--color-text);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
	scroll-behavior: smooth;
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 340px;
}

#rendered-markdown [id] {
    scroll-margin-top: 100px;
}

html {
    scroll-behavior: smooth;
    /* Reserve gutter space from first paint so the scrollbar
       appearing never shifts layout (eliminates CLS). */
    scrollbar-gutter: stable;
}

/* Hide the scrollbar thumb/track until the user actually scrolls.
   The gutter space is still reserved above, so no layout shift occurs. */
html:not(.user-scrolled)::-webkit-scrollbar-thumb {
    background-color: transparent;
}
html:not(.user-scrolled)::-webkit-scrollbar-track {
    background-color: transparent;
}

/* Once .user-scrolled is added by JS, show a styled scrollbar. */
html.user-scrolled::-webkit-scrollbar {
    width: 10px;
}
html.user-scrolled::-webkit-scrollbar-track {
    background: transparent;
}
html.user-scrolled::-webkit-scrollbar-thumb {
    background-color: #4f545c;
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}
html.user-scrolled::-webkit-scrollbar-thumb:hover {
    background-color: #72767d;
}

main {
	width: 100%;
	max-width: 1200px;
	padding: 20px;
	box-sizing: border-box;
	display: grid;
	grid-template-columns: 1fr 280px;
	grid-template-areas:
		"compat compat"
		"content toc";
	column-gap: 24px;
	align-items: start;
}

.compatibility-container {
	grid-area: compat;
	display: flex;
	flex-wrap: wrap;
	gap: 20px;
	margin: 20px 0;
	box-sizing: border-box;
}

#rendered-markdown {
	grid-area: content;
	background: #36393f;
	border-radius: 16px;
	margin: 20px 0;
	padding: 20px;
	text-align: left;
	color: #fff;
	box-sizing: border-box;
	min-width: 0;
	/* Push the footer below the fold before markdown loads so its position
	   change as content renders is off-screen and does not count as CLS. */
	min-height: 100vh;
}

#toc-sidebar {
	grid-area: toc;
	position: sticky;
	top: 100px;
	margin-top: 20px;
	background: #36393f;
	border-radius: 16px;
	padding: 18px 20px;
	box-sizing: border-box;
	max-height: calc(100vh - 100px);
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: #4f545c transparent;
}

#toc-sidebar::-webkit-scrollbar {
	width: 4px;
}

#toc-sidebar::-webkit-scrollbar-thumb {
	background: #4f545c;
	border-radius: 4px;
}

#toc-sidebar h2 {
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: #a0a8b4;
	margin: 0 0 14px 0;
	padding-bottom: 10px;
	border-bottom: 1px solid #4f545c;
}

#toc-sidebar ol {
	margin: 0;
	padding: 0;
	list-style: none;
	counter-reset: toc-counter;
}

#toc-sidebar ol li {
	counter-increment: toc-counter;
	display: flex;
	align-items: baseline;
	gap: 7px;
}

#toc-sidebar ol li::before {
	content: counter(toc-counter) ".";
	font-size: 0.78rem;
	color: #6b7280;
	min-width: 20px;
	flex-shrink: 0;
}

#toc-sidebar ol li a {
	display: block;
	padding: 5px 0;
	font-size: 0.92rem;
	line-height: 1.4;
	text-decoration: none;
	transition: color 0.15s ease;
	word-break: break-word;
	color: #ff6f61;
}

#toc-sidebar ol li a:hover {color: #ff967e;}

#toc-sidebar ol li a.toc-active {
	color: #ffffff;
	font-weight: 600;
}

#toc-drawer {
	display: none;
}

#toc-drawer-toggle {
	width: 5rem;
	background: #36393f;
	border: none;
	padding: 10px;
	text-align: left;
	cursor: pointer;
	color: #f5f5f5;
	font-size: 1.5rem;
	font-weight: 600;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	box-sizing: border-box;
	border-radius: 1rem;
	border: 1px solid white;
}

#toc-drawer-toggle::after {
	content: "▾";
	font-size: 1rem;
	transition: transform 0.2s ease;
	flex-shrink: 0;
}

#toc-drawer-toggle[aria-expanded="true"]::after {
	transform: rotate(180deg);
}

#toc-drawer-body {
	background: #36393f;
	padding: 0px 20px;
	max-height: 0;
	overflow: hidden;
	transition: max-height 0.3s ease, padding 0.3s ease;
}

#toc-drawer-body.open {
	max-height: 600px;
	padding: 12px 18px 16px;
	border-radius: 1rem;
	border: 1px solid white;
	margin-top: 10px;
}

#toc-drawer-body ol {
	margin: 0;
	padding: 0;
	list-style: none;
	counter-reset: toc-counter-d;
}

#toc-drawer-body ol li {
	counter-increment: toc-counter-d;
	display: flex;
	align-items: baseline;
	gap: 7px;
}

#toc-drawer-body ol li::before {
	content: counter(toc-counter-d) ".";
	font-size: 0.8rem;
	color: #6b7280;
	min-width: 20px;
	flex-shrink: 0;
}

#toc-drawer-body ol li a {
	display: block;
	padding: 4px 0;
	font-size: 0.95rem;
	text-decoration: none;
	transition: color 0.15s ease;
	color: #ff6f61;
}

#toc-drawer-body ol li a:hover {
	color: #ff967e;
}

.compatibility-box {
	flex: 1 1 calc(33.33% - 20px);
	min-width: 280px;
	background: #36393f;
	border-radius: 16px;
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	box-sizing: border-box;
}

.compatibility-box h3 {
	font-size: 1.2rem;
	color: #f5f5f5;
	margin-bottom: 10px;
}

.compatibility-box p {
	color: #c9c9c9;
	margin: 5px 0;
}

.compatibility-box a {
	text-decoration: none;
	color: #ff6f61;
	font-weight: 600;
	margin-right: 10px;
	transition: color 0.3s ease;
}

.compatibility-box a:hover {
	color: #ff967e;
}

.download-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 10px;
}

.download-button {
	background-color: #4f545c;
	padding: 10px;
	text-align: center;
	border-radius: 8px;
	color: #fff !important;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 5px;
	transition: background 0.3s;
}

.download-button:hover {
	background-color: #4f545c87;
}

@media (max-width: 1100px) {
	main {
		grid-template-columns: 1fr;
		grid-template-areas:
			"compat"
			"content";
	}

	#toc-sidebar {
		display: none;
	}

	#toc-drawer {
		display: block;
		margin: 0px;
		grid-area: compat;
		position: fixed;
		top: 15px;
		Z-INDEX: 999;
	}
}

@media (max-width: 1024px) {
	.compatibility-container {
		flex-direction: column;
		align-items: center;
	}

	.compatibility-box {
		min-width: 100%;
	}

	.nav-container {
		justify-content: center;
		flex-wrap: wrap;
	}
}

@media (max-width: 768px) {
	.download-grid {
		grid-template-columns: 1fr;
	}

	.compatibility-container {
		gap: 15px;
	}
}