/* A project's code on its page (code.js): the open folder or
   file under the path to it, and from 840px of page width (M3's expanded
   size) a tree of the folders beside it, which stays in view as the page
   scrolls. */

.code-view {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	align-items: start;
	gap: var(--s5);
}

.code-tree {
	display: none;
}

@container page (min-width: 840px) {
	.code-view {
		grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
	}

	/* It sticks where it starts, below the fade under the page's head. */
	.code-tree {
		position: sticky;
		top: var(--s5);
		display: block;
		max-height: calc(100cqh - var(--s5) * 2);
		margin-left: calc(var(--s2) * -1);
		padding-bottom: var(--s4);
		overflow: auto;
		overscroll-behavior: contain;
	}
}

/* Viewing an old commit: what it is, and the way back to the branch. */
.code-banner {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--s2) var(--s3);
	margin-bottom: var(--s3);
	padding: var(--s2) var(--s2) var(--s2) var(--s4);
	border-radius: var(--s3);
	background: var(--selected);
	font-size: 13px;
}

.code-banner[hidden] {
	display: none;
}

.code-banner > svg {
	width: 18px;
	height: 18px;
	flex: none;
}

.code-banner p {
	flex: 1 1 240px;
	margin: 0;
}

.code-banner code {
	font: inherit;
}

.code-banner .code-download {
	height: 32px;
	margin-left: auto;
	font-size: 13px;
}

/* A file's or folder's lines, beside its size. */
.code-lines-count {
	flex: none;
	font-size: 12px;
	color: var(--ink-quiet);
}

.code-lines-count + .code-size::before {
	content: "·";
	margin-right: var(--s2);
}

/* A file: line numbers beside the text, which scrolls sideways on its
   own; the numbers aren't part of the text, so they never copy. */
/* The text sits on the page's background, where every syntax colour
   meets 4.5:1; the numbers on the surface beside it. */
.code-file {
	position: relative;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	border: 1px solid var(--hairline);
	border-radius: var(--s4);
	font-family: var(--font-mono);
	font-size: 13px;
	line-height: 20px;
	overflow: hidden;
}

.code-file pre {
	margin: 0;
	padding: var(--s3) 0;
	font: inherit;
	tab-size: 4;
}

/* The numbers' surface lets a band of chosen lines show through. */
.code-gutter {
	padding-inline: var(--s4) var(--s3) !important;
	background: color-mix(in srgb, var(--surface) 70%, transparent);
	cursor: pointer;
	border-right: 1px solid var(--hairline);
	color: var(--ink-quiet);
	text-align: right;
	user-select: none;
	--selection-line: none;
}

.code-lines {
	padding-inline: var(--s4) !important;
	overflow-x: auto;
}

/* The browser's own monospace would set the lines apart from their
   numbers. */
.code-lines code {
	font: inherit;
}

/* Chosen lines: a band across the numbers and the text. */
.code-selection {
	position: absolute;
	right: 0;
	left: 0;
	z-index: 0;
	background: color-mix(in srgb, var(--yellow) 14%, transparent);
	box-shadow: inset 3px 0 var(--yellow);
	pointer-events: none;
}

.code-selection[hidden] {
	display: none;
}

.code-file pre {
	position: relative;
	z-index: 1;
}

.code-lines:focus-visible {
	outline-offset: -2px;
}

.code-image {
	display: grid;
	place-items: center;
	min-height: 160px;
	padding: var(--s5);
	border: 1px solid var(--hairline);
	border-radius: var(--s4);
	background: var(--surface);
}

.code-image img {
	max-width: 100%;
	height: auto;
}

/* M3's segmented button, for showing a Markdown file rendered or as its
   source: 40px, outlined, fully rounded, and the selected segment filled
   with the primary colour's container and led by a check. Choosing one,
   its fill eases in and its check grows into place as the label makes
   room, on the page's default spatial spring (page.js); the other's goes
   the same way back. */
.code-segments {
	display: inline-flex;
	margin-right: var(--s2);
}

.code-segment {
	appearance: none;
	position: relative;
	display: inline-flex;
	align-items: center;
	height: 40px;
	padding: 0 var(--s4);
	border: 1px solid var(--border);
	background: none;
	color: var(--text);
	font: inherit;
	font-size: 14px;
	transition: background-color 200ms var(--ease-effects);
}

.code-segment:first-child {
	border-radius: 20px 0 0 20px;
}

.code-segment + .code-segment {
	margin-left: -1px;
	border-radius: 0 20px 20px 0;
}

.code-segment svg {
	flex: none;
	width: 0;
	height: 18px;
	margin-right: 0;
	opacity: 0;
	scale: 0.4;
	transition:
		width var(--spring-tab-duration, 300ms) var(--spring-tab, ease),
		margin-right var(--spring-tab-duration, 300ms) var(--spring-tab, ease),
		scale var(--spring-tab-duration, 300ms) var(--spring-tab, ease),
		opacity 150ms var(--ease-effects);
}

.code-segment[aria-pressed="true"] {
	background: var(--selected);
}

.code-segment[aria-pressed="true"] svg {
	width: 18px;
	margin-right: var(--s2);
	opacity: 1;
	scale: 1;
}

.code-segment:hover::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background: currentColor;
	opacity: 0.08;
}

/* The shown form takes no hover layer: choosing it again does nothing,
   and the layer would take its text below 4.5:1. */
.code-segment[aria-pressed="true"]::before {
	display: none;
}

/* A folder's README, under its contents. */
.code-readme {
	margin-top: var(--s5);
	border: 1px solid var(--hairline);
	border-radius: var(--s4);
}

.code-readme-head {
	display: flex;
	align-items: center;
	gap: var(--s2);
	min-height: 48px;
	padding: 0 var(--s4);
	border-bottom: 1px solid var(--hairline);
	font-size: 14px;
}

.code-readme-head svg {
	width: 18px;
	height: 18px;
	color: var(--muted);
}

.code-readme .markdown {
	padding: var(--s5);
}

.code-readme-text {
	margin: 0;
	padding: var(--s5);
	font: inherit;
	font-size: 13px;
	white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
	.code-segment,
	.code-segment svg {
		transition: none;
	}
}
