:root {
	--fg: #33ff66;
	--fg-dim: #1fa847;
	--fg-faint: #0f5a26;
	--fg-hot: #b6ffc8;
	--bg: #000a02;
	--glow: 0 0 2px rgba(51, 255, 102, 0.9), 0 0 8px rgba(51, 255, 102, 0.45), 0 0 18px rgba(51, 255, 102, 0.2);
	--font: "VT323", "Courier New", ui-monospace, monospace;
	--size: clamp(19px, 2.3vw + 10px, 26px);
	--app-h: 100dvh;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	background: #000;
	overflow: hidden;
	overscroll-behavior: none;
}

body {
	color: var(--fg);
	font-family: var(--font);
	font-size: var(--size);
	line-height: 1.18;
	text-shadow: var(--glow);
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;
	-webkit-text-size-adjust: 100%;
}

::selection {
	background: var(--fg);
	color: #000;
	text-shadow: none;
}

/* ---------- matrix rain ---------- */
#rain {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 0;
	opacity: 1;
	transition: opacity 2.5s ease;
	pointer-events: none;
}
#rain.dim {
	opacity: 0.13;
}
#rain.off {
	opacity: 0;
}

/* ---------- CRT container ---------- */
.crt {
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	height: var(--app-h);
	z-index: 1;
	display: flex;
	flex-direction: column;
	padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
	background: radial-gradient(ellipse at center, rgba(0, 40, 10, 0.55) 0%, rgba(0, 10, 2, 0.75) 70%, rgba(0, 0, 0, 0.9) 100%);
	animation: flicker 6s infinite steps(1);
}

.screen {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: var(--fg-faint) transparent;
	padding-bottom: 0.4em;
	max-width: 80ch;
	width: 100%;
	margin: 0 auto;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.screen::-webkit-scrollbar {
	width: 6px;
}
.screen::-webkit-scrollbar-thumb {
	background: var(--fg-faint);
}

/* ---------- lines ---------- */
.line {
	margin: 0;
	min-height: 1.18em;
}
.line.sys {
	color: var(--fg-dim);
}
.line.hot {
	color: var(--fg-hot);
}
.line.err {
	color: #ff5555;
	text-shadow: 0 0 6px rgba(255, 60, 60, 0.6);
}
.line.echo {
	color: var(--fg-hot);
	margin-top: 0.7em;
}
.line.narr {
	margin-top: 0.5em;
}
.line.narr p {
	margin: 0 0 0.6em;
}
.line.narr p:last-child {
	margin-bottom: 0;
}
.line.end {
	margin: 0.8em 0;
	text-align: center;
	letter-spacing: 0.3em;
	color: var(--fg-hot);
}
.banner {
	color: var(--fg-hot);
	/* VT323's block glyph isn't full-width, so use a system mono font for the block letters */
	font-family: "DejaVu Sans Mono", Menlo, Consolas, "Liberation Mono", monospace;
	line-height: 1.02;
	letter-spacing: 0;
	font-size: clamp(6px, 1.25vw, 13px);
	white-space: pre;
	overflow: hidden;
	margin: 0.4em 0 0.6em;
}
.banner-small {
	display: none;
	color: var(--fg-hot);
	font-size: 1.6em;
	letter-spacing: 0.12em;
	margin: 0.3em 0;
}
@media (max-width: 560px) {
	.banner {
		display: none;
	}
	.banner-small {
		display: block;
	}
}

.menu-item {
	display: block;
	color: var(--fg);
	cursor: pointer;
	padding: 0.06em 0;
}
.menu-item .k {
	color: var(--fg-hot);
}
.menu-item .d {
	color: var(--fg-dim);
}
@media (hover: hover) {
	.menu-item:hover {
		background: var(--fg);
		color: #000;
		text-shadow: none;
	}
	.menu-item:hover .k,
	.menu-item:hover .d {
		color: #000;
	}
}

/* streaming narration cursor */
.typing::after {
	content: "\2588";
	animation: blink 0.9s steps(1) infinite;
	margin-left: 1px;
}

/* ---------- prompt ---------- */
.prompt {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-start;
	gap: 0.4em;
	max-width: 80ch;
	width: 100%;
	margin: 0 auto;
	padding: 0.35em 0 0.3em;
	border-top: 1px solid var(--fg-faint);
}
.prompt[hidden] {
	display: none;
}
.prompt-line {
	position: relative;
	flex: 1;
	display: flex;
	gap: 0.5ch;
	min-height: 1.3em;
	cursor: text;
}
.ps1 {
	color: var(--fg-hot);
}
.mirror {
	flex: 1;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	min-width: 0;
}
.cursor {
	background: var(--fg);
	color: #000;
	text-shadow: none;
	box-shadow: 0 0 8px rgba(51, 255, 102, 0.7);
	animation: blink 1.05s steps(1) infinite;
}
.prompt.busy .cursor,
.prompt:not(.focused) .cursor {
	background: transparent;
	color: inherit;
	box-shadow: inset 0 -0.14em 0 var(--fg);
}
.prompt.busy .ps1 {
	animation: blink 0.6s steps(1) infinite;
}
#cmd {
	/* real input sits invisibly on top of the mirrored text */
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	font-size: 16px; /* stops iOS zoom-on-focus */
	border: 0;
	padding: 0;
	margin: 0;
	background: transparent;
	color: transparent;
	caret-color: transparent;
	outline: none;
}
.send {
	flex: 0 0 auto;
	font: inherit;
	color: var(--fg);
	background: transparent;
	border: 1px solid var(--fg-dim);
	text-shadow: var(--glow);
	padding: 0 0.5em;
	line-height: 1.2;
	cursor: pointer;
	display: none;
}
.send:active {
	background: var(--fg);
	color: #000;
}
@media (pointer: coarse) {
	.send {
		display: block;
	}
}

.status {
	flex: 0 0 auto;
	max-width: 80ch;
	width: 100%;
	margin: 0 auto;
	padding: 0.1em 0 max(8px, env(safe-area-inset-bottom));
	color: var(--fg-dim);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	display: flex;
	justify-content: space-between;
	gap: 1em;
}
.status span {
	font-size: 0.72em;
}
.status span:first-child {
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ---------- overlays ---------- */
.overlay {
	position: fixed;
	inset: 0;
	pointer-events: none;
	z-index: 5;
}
.scanlines {
	background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0, 0) 2px, rgba(0, 0, 0, 0.28) 3px, rgba(0, 0, 0, 0) 4px);
}
.scanlines::after {
	/* slow rolling refresh band */
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	height: 18vh;
	top: -20vh;
	background: linear-gradient(to bottom, rgba(51, 255, 102, 0), rgba(51, 255, 102, 0.035), rgba(51, 255, 102, 0));
	animation: roll 8s linear infinite;
}
.vignette {
	background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.55) 100%);
	box-shadow: inset 0 0 90px rgba(0, 0, 0, 0.9);
}

@keyframes blink {
	50% {
		opacity: 0;
	}
}
@keyframes roll {
	to {
		top: 110vh;
	}
}
@keyframes flicker {
	0% { opacity: 1; }
	12% { opacity: 0.985; }
	13% { opacity: 1; }
	47% { opacity: 0.975; }
	48% { opacity: 1; }
	71% { opacity: 0.99; }
	72% { opacity: 0.96; }
	73% { opacity: 1; }
}

.shake {
	animation: shake 0.25s linear;
}
@keyframes shake {
	25% { transform: translateX(-2px); }
	75% { transform: translateX(2px); }
}

@media (prefers-reduced-motion: reduce) {
	.crt,
	.scanlines::after {
		animation: none;
	}
	#rain {
		display: none;
	}
}
