:root {
	--page-pad: clamp(10px, 2.5vh, 24px);
	--calc-max: 460px;
	--bg-1: #0a1020;
	--bg-2: #121d35;
	--panel: rgba(20, 29, 52, 0.45);
	--panel-border: rgba(190, 220, 255, 0.2);
	--text: #e9f0ff;
	--text-muted: #9ca8c9;
	--btn: rgba(255, 255, 255, 0.08);
	--btn-hover: rgba(255, 255, 255, 0.16);
	--op: rgba(85, 133, 255, 0.2);
	--danger: rgba(255, 95, 145, 0.25);
	--accent-grad: linear-gradient(135deg, #4ec7ff, #6e73ff 60%, #a566ff);
	--shadow-1: 0 24px 60px rgba(4, 10, 24, 0.55);
	--shadow-2: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	min-height: 100dvh;
	display: flex;
	justify-content: center;
	align-items: flex-start;
	font-family: "Segoe UI", "Noto Sans", sans-serif;
	color: var(--text);
	background: radial-gradient(circle at 10% 20%, #1f2f55 0%, transparent 35%),
		radial-gradient(circle at 90% 10%, #282061 0%, transparent 30%),
		linear-gradient(145deg, var(--bg-1), var(--bg-2));
	overflow-x: hidden;
	overflow-y: auto;
	padding: var(--page-pad);
	scrollbar-width: none;
}

body::-webkit-scrollbar {
	display: none;
}

.app-bg {
	position: fixed;
	inset: 0;
	pointer-events: none;
}

.blob {
	position: absolute;
	border-radius: 50%;
	filter: blur(8px);
	opacity: 0.5;
	animation: drift 10s ease-in-out infinite alternate;
	will-change: transform;
}

.blob-1 {
	width: 320px;
	height: 320px;
	background: #5e73ff;
	top: -80px;
	left: -70px;
}

.blob-2 {
	width: 260px;
	height: 260px;
	background: #4ec7ff;
	bottom: -60px;
	right: -30px;
	animation-delay: 1.4s;
}

.blob-3 {
	width: 220px;
	height: 220px;
	background: #a566ff;
	top: 38%;
	right: 22%;
	animation-delay: 2.8s;
}

.calculator {
	width: min(100%, var(--calc-max));
	margin: auto;
	display: flex;
	flex-direction: column;
	background: var(--panel);
	border: 1px solid var(--panel-border);
	border-radius: 24px;
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	box-shadow: var(--shadow-1), var(--shadow-2);
	padding: 18px;
	position: relative;
	z-index: 1;
	animation: rise 650ms ease;
}

.topbar {
	display: flex;
	justify-content: center;
	gap: 12px;
	margin-bottom: 18px;
	flex-wrap: wrap;
}

.toggles {
	display: flex;
	width: 100%;
	justify-content: center;
	gap: 8px;
	flex-wrap: wrap;
}

.chip {
	border: 0;
	border-radius: 999px;
	padding: 8px 12px;
	font-size: 12px;
	letter-spacing: 0.5px;
	color: var(--text);
	background: rgba(255, 255, 255, 0.09);
	cursor: pointer;
	transition: 180ms ease;
}

.chip:hover {
	transform: translateY(-1px);
	background: rgba(255, 255, 255, 0.16);
}

.chip.active {
	background-image: var(--accent-grad);
	box-shadow: 0 0 18px rgba(102, 177, 255, 0.45);
	color: #09101f;
	font-weight: 700;
}

.display {
	background: rgba(7, 14, 28, 0.55);
	border: 1px solid rgba(165, 194, 255, 0.22);
	border-radius: 20px;
	padding: 14px;
	margin-bottom: 16px;
	min-height: 102px;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
	position: relative;
	overflow: hidden;
	transition: min-height 180ms ease;
}

.display.tool-open {
	min-height: 220px;
}

.display.tool-open[data-tool="differentiate"] {
	min-height: 136px;
}

.display.tool-open[data-tool="differentiate"] .calc-tool {
	gap: 5px;
	padding-top: 10px;
	padding-bottom: 10px;
}

.display.tool-open[data-tool="differentiate"] .calc-tool-fields {
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 6px;
}

.display.tool-open[data-tool="differentiate"] .calc-tool-actions {
	margin-top: 2px;
}

.display.tool-open[data-tool="integrate"],
.display.tool-open[data-tool="cubic"] {
	min-height: 186px;
}

.expression,
.result {
	margin: 0;
	text-align: right;
	word-wrap: break-word;
}

.expression {
	color: var(--text-muted);
	min-height: 24px;
	font-size: 0.95rem;
}

.result {
	margin-top: 10px;
	min-height: 42px;
	font-size: clamp(1.55rem, 3.4vw, 2rem);
	font-weight: 700;
}

.calc-tool {
	position: absolute;
	inset: 0;
	z-index: 2;
	border-radius: 20px;
	padding: 14px;
	background: rgba(5, 13, 28, 0.58);
	border: 1px solid rgba(159, 193, 255, 0.24);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
	animation: rise 220ms ease;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.display.tool-open .expression,
.display.tool-open .result {
	opacity: 0;
	pointer-events: none;
}

.hidden {
	display: none;
}

.calc-tool-title {
	margin: 0 0 8px;
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.4px;
	color: #b9c9f6;
	text-transform: uppercase;
}

.calc-tool-fields {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 8px;
	overflow: visible;
	padding-right: 0;
	align-content: start;
}

.calc-tool-field {
	border: 1px solid rgba(172, 202, 255, 0.2);
	border-radius: 10px;
	padding: 7px 9px;
	min-height: 40px;
	background: rgba(255, 255, 255, 0.03);
	color: var(--text);
	text-align: left;
	font-family: inherit;
	font-size: 0.8rem;
	display: flex;
	justify-content: space-between;
	gap: 12px;
	cursor: pointer;
	transition: 140ms ease;
}

.calc-tool-field:hover {
	background: rgba(255, 255, 255, 0.08);
}

.calc-tool-field.active {
	border-color: rgba(122, 179, 255, 0.8);
	box-shadow: 0 0 14px rgba(92, 167, 255, 0.28);
	background: rgba(85, 133, 255, 0.16);
}

.calc-tool-quick {
	justify-content: center;
	background: rgba(78, 129, 255, 0.12);
	border-style: dashed;
}

.calc-tool-quick-label {
	font-size: 1rem;
	font-weight: 700;
	text-transform: lowercase;
	color: #cddcff;
}

.calc-tool-label {
	color: #9fb5e8;
	font-weight: 600;
	white-space: nowrap;
}

.calc-tool-value {
	flex: 1;
	text-align: right;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.calc-tool-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 4px;
}

.keypad {
	display: grid;
	grid-template-columns: repeat(5, minmax(56px, 1fr));
	grid-auto-rows: clamp(56px, 8.2vh, 74px);
	gap: clamp(8px, 1.8vw, 12px);
	width: min(100%, 470px);
	margin-inline: auto;
	margin-top: 2px;
}

.btn {
	border: 0;
	border-radius: 16px;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	min-height: 0;
	font-size: 1rem;
	font-weight: 600;
	color: var(--text);
	background: var(--btn);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 8px 20px rgba(3, 8, 18, 0.35);
	cursor: pointer;
	transition: transform 120ms ease, background 160ms ease, box-shadow 200ms ease;
	user-select: none;
	touch-action: manipulation;
}

.btn:hover {
	transform: translateY(-2px);
	background: var(--btn-hover);
}

.btn:active {
	transform: translateY(1px) scale(0.98);
}

.btn-op {
	background: var(--op);
	color: #cde3ff;
}

.btn-danger {
	background: var(--danger);
}

.btn-equals {
	background-image: var(--accent-grad);
	color: #06121b;
	font-weight: 700;
	box-shadow: 0 0 20px rgba(96, 174, 255, 0.55), 0 12px 30px rgba(7, 11, 25, 0.4);
}

.github-fab {
	position: relative;
	margin-left: auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 1px solid rgba(190, 220, 255, 0.35);
	border-radius: 50%;
	color: var(--text);
	text-decoration: none;
	background: rgba(8, 15, 30, 0.68);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	box-shadow: 0 8px 20px rgba(3, 8, 18, 0.4);
	transition: transform 120ms ease, background 160ms ease, box-shadow 200ms ease;
	touch-action: manipulation;
}

.github-icon {
	width: 22px;
	height: 22px;
	display: block;
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.github-fab:hover {
	transform: translateY(-2px);
	background: rgba(20, 36, 64, 0.85);
}

.github-fab:active {
	transform: translateY(1px) scale(0.98);
}

@media (max-width: 560px) {
	.blob {
		animation: none;
		filter: none;
		opacity: 0.3;
	}

	.calculator {
		backdrop-filter: none;
		-webkit-backdrop-filter: none;
		box-shadow: 0 12px 28px rgba(4, 10, 24, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
	}

	.calculator {
		padding: 14px;
		border-radius: 20px;
		width: min(100%, 460px);
	}

	.toggles {
		justify-content: flex-end;
	}

	.keypad {
		grid-template-columns: repeat(5, minmax(0, 1fr));
		grid-auto-rows: clamp(50px, 12vw, 64px);
		gap: 8px;
		width: 100%;
	}

	.btn {
		font-size: 0.96rem;
	}

	.topbar {
		gap: 10px;
	}

	.github-fab {
		width: 40px;
		height: 40px;
		backdrop-filter: none;
		-webkit-backdrop-filter: none;
		box-shadow: 0 4px 12px rgba(3, 8, 18, 0.28);
	}

	.github-icon {
		width: 20px;
		height: 20px;
	}

	.btn,
	.chip,
	.github-fab {
		transition-duration: 90ms;
	}
}

@media (prefers-reduced-motion: reduce) {
	.blob,
	.calculator,
	.calc-tool,
	.btn,
	.chip {
		animation: none !important;
		transition: none !important;
	}
}

@media (max-width: 420px) {
	:root {
		--page-pad: 8px;
	}

	body {
		scrollbar-width: auto;
	}

	body::-webkit-scrollbar {
		display: block;
	}

	.calculator {
		padding: 12px;
	}

	.display {
		padding: 12px;
		min-height: 92px;
	}

	.calc-tool-fields {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 6px;
	}
}

@keyframes drift {
	from {
		transform: translate(0, 0) scale(1);
	}
	to {
		transform: translate(14px, -12px) scale(1.08);
	}
}

@keyframes rise {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}
