/* Terminal overlay */
.terminal {
	position: fixed;
	inset: 0;
	z-index: 3000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 3em;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s ease, visibility 0.3s ease;
	font-family: var(--terminal-font, ui-monospace, "Cascadia Code", "Courier New", monospace);
}

.terminal--open {
	opacity: 1;
	visibility: visible;
}

.terminal__backdrop {
	position: absolute;
	inset: 0;
	background:
		radial-gradient(circle at 50% 35%, rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.07), transparent 60%),
		rgba(1, 1, 1, 0.8);
	backdrop-filter: blur(8px) saturate(1.15);
	-webkit-backdrop-filter: blur(8px) saturate(1.15);
}

.terminal__panel {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 52em;
	height: min(70vh, 42em);
	background: linear-gradient(180deg, rgba(8, 12, 8, 0.97) 0%, var(--body-bg) 55%);
	border: 1px solid rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.4);
	box-shadow:
		0 0 32px -6px rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.35),
		0 30px 70px -20px rgba(0, 0, 0, 0.85);
	transform: scale(0.92) translateY(14px);
	filter: blur(6px);
	transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1), filter 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.terminal--open .terminal__panel {
	transform: scale(1) translateY(0);
	filter: blur(0);
	animation: terminalPulse 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes terminalPulse {
	0% {
		box-shadow:
			0 0 0 rgba(var(--body-text-alt-rgb, 50, 188, 21), 0),
			0 30px 70px -20px rgba(0, 0, 0, 0.85);
	}
	45% {
		box-shadow:
			0 0 60px 6px rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.5),
			0 30px 70px -20px rgba(0, 0, 0, 0.85);
	}
	100% {
		box-shadow:
			0 0 32px -6px rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.35),
			0 30px 70px -20px rgba(0, 0, 0, 0.85);
	}
}

/* HUD corner brackets — same technique as .modal__panel::before */
.terminal__panel::before {
	content: '';
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 0;
	--bc: rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.9);
	background-image:
		linear-gradient(var(--bc), var(--bc)), linear-gradient(var(--bc), var(--bc)),
		linear-gradient(var(--bc), var(--bc)), linear-gradient(var(--bc), var(--bc)),
		linear-gradient(var(--bc), var(--bc)), linear-gradient(var(--bc), var(--bc)),
		linear-gradient(var(--bc), var(--bc)), linear-gradient(var(--bc), var(--bc));
	background-repeat: no-repeat;
	background-size:
		1.25em 2px, 2px 1.25em,
		1.25em 2px, 2px 1.25em,
		1.25em 2px, 2px 1.25em,
		1.25em 2px, 2px 1.25em;
	background-position:
		top -1px left -1px, top -1px left -1px,
		top -1px right -1px, top -1px right -1px,
		bottom -1px right -1px, bottom -1px right -1px,
		bottom -1px left -1px, bottom -1px left -1px;
	opacity: 0;
	transition: opacity 0.4s ease 0.15s;
}

.terminal--open .terminal__panel::before {
	opacity: 1;
}

/* Faint scanline texture — same technique as .modal__panel::after */
.terminal__panel::after {
	content: '';
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 0;
	background-image: repeating-linear-gradient(
		180deg,
		rgba(255, 255, 255, 0.015) 0px,
		rgba(255, 255, 255, 0.015) 1px,
		transparent 1px,
		transparent 3px
	);
	mix-blend-mode: overlay;
	opacity: 0;
	transition: opacity 0.5s ease 0.1s;
}

.terminal--open .terminal__panel::after {
	opacity: 1;
}

.terminal__titlebar {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	gap: 0.75em;
	padding: 0.75em 1em;
	border-bottom: 1px solid rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.35);
	background: rgba(0, 0, 0, 0.35);
	flex-shrink: 0;
}

.terminal__dots {
	display: flex;
	gap: 0.4em;
}

.terminal__dots span {
	width: 0.7em;
	height: 0.7em;
	border-radius: 50%;
	background: rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.35);
}

.terminal__title {
	flex: 1 1 auto;
	text-align: center;
	font-size: 0.8em;
	letter-spacing: 0.02em;
	color: rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.75);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.terminal__close {
	flex-shrink: 0;
	width: 2em;
	height: 2em;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1px solid rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.35);
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.5);
	color: var(--link-text-hover);
	cursor: pointer;
	transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.terminal__close .icon {
	width: 1.1em;
	height: 1.1em;
	margin: 0;
}

.terminal__close:hover,
.terminal__close:focus-visible {
	color: var(--body-text-alt);
	background: rgba(0, 0, 0, 0.75);
	border-color: var(--body-text-alt);
	transform: scale(1.08);
	box-shadow: 0 0 16px rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.6);
}

.terminal__matrix {
	position: fixed;
	z-index: 3001;
	display: none;
	background: #000;
	pointer-events: none;
}

.terminal__matrix--active {
	display: block;
}

.terminal__log {
	position: relative;
	z-index: 1;
	flex: 1 1 auto;
	min-height: 0;
	overflow-x: hidden;
	overflow-y: auto;
	padding: 1em 1.25em;
	font-size: 0.9em;
	line-height: 1.6;
	color: #e0e0e0;
}

.terminal__line {
	margin: 0 0 0.35em;
	white-space: pre-wrap;
	word-break: break-word;
}

.terminal__line--cmd {
	color: rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.85);
}

.terminal__line--cmd::before {
	content: '> ';
}

.terminal__line--error {
	color: #ff6b5e;
}

.terminal__log a {
	color: var(--body-text-alt);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.terminal__log a:hover,
.terminal__log a:focus-visible {
	color: #fff;
}

.terminal__inputline {
	position: relative;
	z-index: 1;
	flex-shrink: 0;
	display: flex;
	align-items: center;
	padding: 0.75em 1.25em;
	border-top: 1px solid rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.35);
	transition: box-shadow 0.2s ease;
}

.terminal__inputline:focus-within {
	box-shadow: inset 0 1px 0 rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.6);
}

.terminal__prompt {
	flex-shrink: 0;
	margin-right: 0.5em;
	color: rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.85);
	font-size: 0.9em;
	user-select: none;
}

.terminal__input {
	flex: 0 1 auto;
	width: 1ch;
	min-width: 1ch;
	max-width: 100%;
	background: none;
	border: 0;
	outline: none;
	box-shadow: none;
	appearance: none;
	-webkit-appearance: none;
	font: inherit;
	font-size: 0.9em;
	color: #e0e0e0;
	caret-color: transparent;
	padding: 0;
}

.terminal__cursor {
	flex-shrink: 0;
	width: 0.55em;
	height: 1.1em;
	background: var(--body-text-alt);
	box-shadow: 0 0 6px rgba(var(--body-text-alt-rgb, 50, 188, 21), 0.8);
	animation: terminalBlink 1s steps(1) infinite;
}

@keyframes terminalBlink {
	0%, 49% { opacity: 1; }
	50%, 100% { opacity: 0; }
}

@media screen and (max-width: 40em) {
	.terminal {
		padding: 0;
	}

	.terminal__panel {
		max-width: none;
		width: 100%;
		height: 100%;
	}

	.terminal__inputline {
		padding-bottom: max(0.75em, env(safe-area-inset-bottom));
	}

	.terminal__panel::before {
		background-size:
			1em 2px, 2px 1em,
			1em 2px, 2px 1em,
			1em 2px, 2px 1em,
			1em 2px, 2px 1em;
	}
}

@media (prefers-reduced-motion: reduce) {
	.terminal,
	.terminal__panel,
	.terminal__panel::before,
	.terminal__panel::after,
	.terminal__cursor {
		transition-duration: 0.001s;
		animation: none;
	}

	.terminal__panel {
		transform: none;
		filter: none;
	}

	.terminal__cursor {
		opacity: 1;
	}
}
