/* NodeCode — frontend styles.
 * Dual themes: spans carry --nodecode-light / --nodecode-dark variables (defaultColor:false).
 * Light is the default here; dark overrides are emitted dynamically by the plugin
 * under the configured dark-mode selector (see Assets::dynamic_css()).
 */

.nodecode {
	position: relative;
	margin: 1.4em 0;
	border-radius: 8px;
	overflow: hidden;
	font-size: 14px;
	line-height: 1.6;
	border: 1px solid rgba(127, 127, 127, 0.18);
	/* Signal that this block manages its own light/dark scheme so browsers and
	 * extensions (e.g. Dark Reader) avoid force-darkening it. Overridden to
	 * `dark` by the plugin's dynamic CSS when the active strategy goes dark. */
	color-scheme: light;
}

.nodecode pre.nodecode-pre,
.nodecode pre.shiki {
	margin: 0;
	padding: 16px 18px;
	overflow-x: auto;
	background-color: var(--nodecode-light-bg);
	color: var(--nodecode-light);
	tab-size: 4;
	-moz-tab-size: 4;
}

.nodecode pre.nodecode-pre span {
	color: var(--nodecode-light);
}

.nodecode pre.nodecode-pre code {
	display: block;
	width: fit-content;
	min-width: 100%;
	font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
		"Liberation Mono", monospace;
}

.nodecode .line {
	display: inline-block;
	width: 100%;
	box-sizing: border-box;
}

/* ---------- Title / language bar ---------- */

.nodecode-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 12px;
	font-size: 12px;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	background: rgba(127, 127, 127, 0.08);
	border-bottom: 1px solid rgba(127, 127, 127, 0.15);
	color: rgba(127, 127, 127, 0.95);
}

.nodecode-bar .nodecode-title {
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.nodecode-bar .nodecode-lang {
	text-transform: uppercase;
	letter-spacing: 0.04em;
	opacity: 0.8;
}

/* ---------- Toolbar (copy / wrap buttons) ---------- */

.nodecode-toolbar {
	position: absolute;
	top: 6px;
	right: 8px;
	display: flex;
	gap: 6px;
	opacity: 0;
	transition: opacity 0.15s ease;
	z-index: 2;
}

.nodecode.has-bar .nodecode-toolbar {
	top: 4px;
}

.nodecode:hover .nodecode-toolbar,
.nodecode:focus-within .nodecode-toolbar {
	opacity: 1;
}

.nodecode-btn {
	appearance: none;
	cursor: pointer;
	border: 1px solid rgba(127, 127, 127, 0.3);
	background: rgba(127, 127, 127, 0.12);
	color: inherit;
	border-radius: 5px;
	padding: 3px 8px;
	font-size: 11px;
	line-height: 1.4;
	backdrop-filter: blur(4px);
}

.nodecode-btn:hover {
	background: rgba(127, 127, 127, 0.22);
}

.nodecode-btn.is-active {
	background: rgba(99, 102, 241, 0.25);
	border-color: rgba(99, 102, 241, 0.5);
}

/* ---------- Line numbers ---------- */

.nodecode pre.nodecode-pre.has-line-numbers code {
	counter-reset: nodecode-line;
}

.nodecode pre.nodecode-pre.has-line-numbers .line::before {
	counter-increment: nodecode-line;
	content: counter(nodecode-line);
	display: inline-block;
	width: 2.2em;
	margin-right: 1.2em;
	text-align: right;
	color: rgba(127, 127, 127, 0.55);
	user-select: none;
}

/* ---------- Soft wrap (toggled by JS on the <pre>) ---------- */

.nodecode pre.nodecode-pre.is-wrapped,
.nodecode pre.nodecode-pre.is-wrapped code {
	white-space: pre-wrap;
	word-break: break-word;
}

.nodecode pre.nodecode-pre.is-wrapped code {
	width: 100%;
}

/* ---------- Line highlight (transformerNotationHighlight) ---------- */

.nodecode .line.highlighted {
	background: rgba(101, 117, 133, 0.16);
	box-shadow: inset 3px 0 0 rgba(99, 102, 241, 0.7);
}

.nodecode .highlighted-word {
	background: rgba(101, 117, 133, 0.18);
	border-radius: 3px;
	padding: 1px 2px;
}

/* ---------- Diff (transformerNotationDiff) ---------- */

.nodecode .line.diff {
	position: relative;
}

.nodecode .line.diff.add {
	background: rgba(46, 160, 67, 0.16);
}

.nodecode .line.diff.remove {
	background: rgba(248, 81, 73, 0.16);
	opacity: 0.85;
}

.nodecode pre.nodecode-pre:not(.has-line-numbers) .line.diff.add::before {
	content: "+";
	position: absolute;
	left: -1.2em;
	color: rgba(46, 160, 67, 0.9);
}

.nodecode pre.nodecode-pre:not(.has-line-numbers) .line.diff.remove::before {
	content: "-";
	position: absolute;
	left: -1.2em;
	color: rgba(248, 81, 73, 0.9);
}

/* When no line numbers, reserve a small gutter for the +/- markers. */
.nodecode pre.nodecode-pre:not(.has-line-numbers) code {
	padding-left: 1.4em;
}

/* ---------- Focus (transformerNotationFocus) ---------- */

.nodecode .has-focused .line:not(.focused) {
	filter: blur(0.085rem);
	opacity: 0.55;
	transition: filter 0.2s, opacity 0.2s;
}

.nodecode:hover .has-focused .line:not(.focused) {
	filter: blur(0);
	opacity: 1;
}

/* ---------- Collapse long blocks ---------- */

.nodecode.is-collapsible .nodecode-scroller {
	max-height: var(--nodecode-collapse-max, 400px);
	overflow: hidden;
	position: relative;
}

.nodecode.is-collapsible.is-expanded .nodecode-scroller {
	max-height: none;
}

.nodecode.is-collapsible:not(.is-expanded) .nodecode-scroller::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 48px;
	/* --nodecode-bg is set by JS from the rendered <pre> background so the fade
	 * matches whichever theme (light/dark) is currently active. */
	background: linear-gradient(to bottom, transparent, var(--nodecode-bg, var(--nodecode-light-bg)));
	pointer-events: none;
}

.nodecode-expand {
	display: block;
	width: 100%;
	border: none;
	border-top: 1px solid rgba(127, 127, 127, 0.15);
	background: rgba(127, 127, 127, 0.08);
	color: inherit;
	cursor: pointer;
	padding: 6px;
	font-size: 12px;
}

.nodecode-expand:hover {
	background: rgba(127, 127, 127, 0.16);
}

/* ---------- Fallback (service unavailable) ---------- */

.nodecode-fallback pre {
	margin: 0;
	padding: 16px 18px;
	overflow-x: auto;
	background: #f6f8fa;
	color: #24292f;
}
