* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

:root {
	--device-aspect: 0.453333;
	--device-max-width: 420px;
	--screen-x: 0.123529;
	--screen-y: 0.065;
	--screen-w: 0.723529;
	--screen-h: 0.221333;
	--screen-gap: 0.025;
	--bottom-bezel: 0.035;
}

html,
body {
	height: 100%;
	background-color: #2c2c2c;
}

html {
	font-size: clamp(8px, 2.2vmin, 20px);
}

body {
	background-color: #2c2c2c;
	color: #fff;
	font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
	min-height: 100svh;
	display: grid;
	place-items: center;
	padding: 0;
}

.header {
	flex: 0 0 auto;
}

.header h1 {
	font-size: 1.1em;
	font-weight: normal;
}

.rpn-label {
	color: #888;
	font-size: 0.75em;
	margin-bottom: 0.4em;
}

.app-stage {
	width: 100%;
	height: 100%;
	display: grid;
	place-items: center;
	padding: calc(1rem + env(safe-area-inset-top))
		calc(1rem + env(safe-area-inset-right))
		calc(1rem + env(safe-area-inset-bottom))
		calc(1rem + env(safe-area-inset-left));
}

.device-shell {
	position: relative;
	aspect-ratio: 680 / 1500;
	width: min(
		100%,
		var(--device-max-width),
		calc((100svh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)) *
			var(--device-aspect))
	);
	max-height: calc(var(--device-max-width) / var(--device-aspect));
	background: #1b1b1b;
	border-radius: 1.5rem;
	box-shadow: 0 1.25rem 3.125rem rgba(0, 0, 0, 0.45);
	overflow: hidden;
	container-type: inline-size;
}

.device-top {
	position: absolute;
	left: calc(var(--screen-x) * 100%);
	right: calc(var(--screen-x) * 100%);
	top: 0;
	height: calc(var(--screen-y) * 100%);
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
}

.device-screen {
	position: absolute;
	left: calc(var(--screen-x) * 100%);
	top: calc(var(--screen-y) * 100%);
	width: calc(var(--screen-w) * 100%);
	height: calc(var(--screen-h) * 100%);
}

.device-keypad {
	position: absolute;
	left: calc(var(--screen-x) * 100%);
	right: calc(var(--screen-x) * 100%);
	top: calc((var(--screen-y) + var(--screen-h) + var(--screen-gap)) * 100%);
	bottom: calc(var(--bottom-bezel) * 100%);
	display: flex;
	min-height: 0;
}

.stack-container {
	flex: 0 0 auto;
	width: 100%;
	height: 100%;
	background-color: #1a1a1a;
	border-radius: 0.5rem;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.stack-header {
	display: grid;
	grid-template-columns: 3.2em 1fr 1fr;
	background-color: #333;
	padding: 0.6em 0.7em;
	font-size: 0.85em;
	color: #888;
	border-bottom: 0.0625rem solid #444;
}

.stack-row {
	display: grid;
	grid-template-columns: 3.2em 1fr 1fr;
	padding: 0.6em 0.7em;
	border-bottom: 0.0625rem solid #333;
	min-height: 2.6em;
	align-items: center;
}

.stack-row.current {
	background-color: #252525;
}

.stack-label {
	color: #666;
	font-size: 0.85em;
}

.stack-symbolic {
	color: #fff;
	font-size: 1em;
	overflow-x: auto;
	overflow-y: hidden;
	white-space: nowrap;
}

.stack-simplified {
	color: #aaa;
	font-size: 1em;
	overflow-x: auto;
	overflow-y: hidden;
	white-space: nowrap;
}

.keypad-container {
	flex: 1;
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	grid-auto-rows: minmax(0, 1fr);
	gap: 0.625rem;
	width: 100%;
	height: 100%;
	min-height: 0;
}

.keypad-btn.enter {
	grid-column: span 2;
}

.keypad-btn.clear {
	grid-column: span 2;
}

.keypad-btn {
	background-color: #444;
	border: none;
	color: #fff;
	padding: 0.45em 0.5em;
	font-size: 1em;
	font-family: inherit;
	border-radius: 0.25rem;
	cursor: pointer;
	transition:
		background-color 0.2s,
		transform 80ms ease,
		box-shadow 80ms ease;
	box-shadow:
		0 0.25rem 0 #2a2a2a,
		0 0.5rem 1rem rgba(0, 0, 0, 0.35);
	min-height: 0;
	transform: translateZ(0);
}

.keypad-btn:hover {
	background-color: #555;
}

.keypad-btn:active {
	background-color: #666;
	transform: translateY(0.125rem) scale(0.98);
	box-shadow:
		0 0.125rem 0 #1f1f1f,
		0 0.25rem 0.625rem rgba(0, 0, 0, 0.4);
}

/* Task 15: Keyboard press visual feedback */
.keypad-btn.keyboard-active {
	animation: keyPressPulse 150ms ease-out;
	transform: translateY(0.125rem) scale(0.98);
	box-shadow:
		0 0.125rem 0 #1f1f1f,
		0 0.25rem 0.625rem rgba(0, 0, 0, 0.4);
}

@keyframes keyPressPulse {
	0% {
		transform: scale(1);
		box-shadow: 0 0 0 rgba(79, 195, 247, 0);
	}
	50% {
		transform: scale(0.95);
		box-shadow: 0 0 0.625rem rgba(79, 195, 247, 0.5);
	}
	100% {
		transform: scale(1);
		box-shadow: 0 0 0 rgba(79, 195, 247, 0);
	}
}

.keypad-btn.digit {
	background-color: #3a3a3a;
}

.keypad-btn.digit:hover {
	background-color: #4a4a4a;
}

.keypad-btn.operator {
	background-color: #5c5c5c;
}

.keypad-btn.operator:hover {
	background-color: #777;
}

.keypad-btn.enter {
	background-color: #2d5a2d;
}

.keypad-btn.enter:hover {
	background-color: #3d6a3d;
}

.keypad-btn.clear {
	background-color: #5a3a3a;
}

.keypad-btn.clear:hover {
	background-color: #6a4a4a;
}

.keypad-btn.drop,
.keypad-btn.swap {
	background-color: #4a4a5a;
}

.keypad-btn.drop:hover,
.keypad-btn.swap:hover {
	background-color: #5a5a6a;
}

.keypad-btn.unary {
	background-color: #5a4a4a;
}

.keypad-btn.unary:hover {
	background-color: #6a5a5a;
}

.stack-content {
	overflow-y: auto;
	flex: 1;
}

.current-input {
	display: grid;
	grid-template-columns: 3.2em 1fr 1fr;
	padding: 0.6em 0.7em;
	background-color: #252525;
	border-top: 0.125rem solid #444;
	align-items: center;
}

.input-label {
	color: #888;
	font-size: 0.85em;
}

.input-buffer {
	color: #4fc3f7;
	font-size: 1em;
	min-height: 1.5em;
}

.input-simplified {
	color: #aaa;
	font-size: 1em;
	overflow-x: auto;
	white-space: nowrap;
}

/* Task 16: MathJax styling for pretty symbolic rendering */
.stack-symbolic .math-container,
.stack-simplified .math-container,
.input-buffer .math-container {
	display: inline-block;
	vertical-align: middle;
	max-width: 100%;
	overflow-x: auto;
}

.stack-symbolic mjx-container,
.stack-simplified mjx-container,
.input-buffer mjx-container {
	color: inherit;
	font-size: 1em;
}

.stack-symbolic {
	/* Allow MathJax to take full width */
	min-width: 0;
}

.stack-simplified {
	min-width: 0;
}

.ios-haptic-toggle {
	position: fixed;
	left: -62.5rem;
	top: -62.5rem;
	width: 3rem;
	height: 1.75rem;
	opacity: 0;
	pointer-events: none;
}

@media (max-width: 800px) {
	.app-stage {
		padding: 0;
	}

	.device-shell {
		border-radius: 0;
		box-shadow: none;
		width: 100%;
		max-height: none;
	}
}
