/**
 * Code box: filename, language, copy, bounded height, syntax colours.
 * Loaded only on pages that actually render a code block.
 */

/* The box is always a dark surface, in both site themes, so its own colours
   are declared here rather than taken from the theme tokens. --em-muted is
   #64748b in the light theme, which on this near-black header bar was dark
   grey on dark grey. */
.em-code-box-enhanced {
	--emc-bg: var(--em-code-bg);
	--emc-head: rgba(255, 255, 255, 0.055);
	--emc-line: rgba(255, 255, 255, 0.11);
	--emc-text: #e6ebf3;
	--emc-dim: #a3b1c4;

	position: relative;
	margin: 1.75rem 0;
	border: 1px solid var(--emc-line);
	border-radius: 0.55rem;
	background: var(--emc-bg);
	overflow: hidden;
}

.em-code-box-enhanced .em-code-box-head {
	display: flex;
	align-items: center;
	gap: 0.7rem;
	/* Lighter than the code below it, not darker: the label has to sit on
	   top of the block, not sink behind it. */
	padding: 0.55rem 0.6rem 0.55rem 1rem;
	background: var(--emc-head);
	border-bottom: 1px solid var(--emc-line);
	min-height: 2.75rem;
}

.em-code-box-file {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.85rem;
	line-height: 1.3;
	color: var(--emc-text);
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.em-code-box-enhanced .em-code-box-lang {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.72rem;
	font-weight: 500;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: var(--emc-dim);
	border: 1px solid var(--emc-line);
	border-radius: 3px;
	padding: 0.15rem 0.45rem;
	white-space: nowrap;
}

.em-code-box-enhanced .em-code-box-copy {
	margin-inline-start: auto;
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.75rem;
	font-weight: 500;
	padding: 0.35rem 0.8rem;
	border-radius: 0.3rem;
	border: 1px solid var(--emc-line);
	background: transparent;
	color: var(--emc-text);
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.em-code-box-enhanced .em-code-box-copy:hover,
.em-code-box-enhanced .em-code-box-copy:focus-visible {
	background: rgba(255, 255, 255, 0.09);
	border-color: rgba(255, 255, 255, 0.24);
}

.em-code-box-enhanced .em-code-box-copy:focus-visible {
	outline: 2px solid var(--em-primary);
	outline-offset: 1px;
}

.em-code-box-enhanced .em-code-box-copy.is-copied {
	color: #F5A524;
	border-color: rgba(245, 165, 36, 0.55);
}

.em-code-box-enhanced .em-code-box-pre {
	margin: 0;
	padding: 1.1rem 1.2rem;
	/* Long blocks scroll instead of pushing the rest of the page away. */
	max-height: 30rem;
	overflow: auto;
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.9rem;
	line-height: 1.75;
	color: var(--emc-text);
	tab-size: 2;
}

.em-code-box-enhanced .em-code-box-pre code {
	background: none;
	padding: 0;
	color: inherit;
	font-size: inherit;
	white-space: pre;
}

.em-code-box-enhanced .em-code-box-pre::-webkit-scrollbar {
	height: 10px;
	width: 10px;
}

.em-code-box-enhanced .em-code-box-pre::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.16);
	border-radius: 5px;
}

/* ---------- syntax colours, tuned to the navy palette ---------- */
/* Amber, sky, sand and clay: four hues that stay apart from each other and
   from the blue the page already uses for links. */
.hljs-comment,
.hljs-quote {
	color: #6B7C96;
	font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag {
	color: #F5A524;
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute {
	color: #7FC8E8;
}

.hljs-number,
.hljs-variable,
.hljs-template-variable,
.hljs-type,
.hljs-built_in {
	color: #E8B87C;
}

.hljs-title,
.hljs-section,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
	color: #A8C8F0;
}

.hljs-meta,
.hljs-symbol,
.hljs-bullet,
.hljs-link {
	color: #D98E63;
}

.hljs-deletion {
	color: #F0908A;
}

.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- narrow screens ---------- */
@media (max-width: 560px) {
	.em-code-box-enhanced .em-code-box-head {
		flex-wrap: wrap;
		gap: 0.4rem;
	}

	.em-code-box-file {
		max-width: 55%;
	}

	.em-code-box-enhanced .em-code-box-pre {
		font-size: 0.84rem;
		line-height: 1.7;
		max-height: 24rem;
	}
}

/* ---------- print ---------- */
@media print {
	.em-code-box-enhanced {
		border: 1px solid #ccc;
		background: #fafafa;
	}

	.em-code-box-enhanced .em-code-box-copy {
		display: none;
	}

	.em-code-box-enhanced .em-code-box-head {
		background: #eee;
		border-bottom: 1px solid #ccc;
	}

	.em-code-box-file,
	.em-code-box-enhanced .em-code-box-lang {
		color: #333;
	}

	.em-code-box-enhanced .em-code-box-pre {
		/* Paper has no scrollbars. */
		max-height: none;
		overflow: visible;
		color: #000;
		white-space: pre-wrap;
		word-break: break-word;
	}

	.em-code-box-enhanced .em-code-box-pre code,
	.em-code-box-enhanced .em-code-box-pre [class^="hljs-"] {
		color: #000 !important;
	}
}

@media (prefers-reduced-motion: reduce) {
	.em-code-box-enhanced .em-code-box-copy {
		transition: none;
	}
}
