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

html, body {
	overflow: hidden;
	touch-action: manipulation;
	-ms-touch-action: manipulation;
	overscroll-behavior: none;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
	background-color: #111;
}

canvas {
	display: block;
	position: fixed;
	top: 0;
	left: 0;
	z-index: 1;
}

@keyframes rotate-on-click {
	0% {
		transform: rotate(0deg);
	}
	50% {
		transform: rotate(180deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

.rotating {
	animation: rotate-on-click 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}

#settings-icon,
#toggle-button {
	position: fixed;
	width: 40px;
	height: 40px;
	background-color: rgba(28, 28, 30, 0.85);
	backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 50%;
	cursor: pointer;
	padding: 8px;
	transition: transform 0.4s cubic-bezier(0.5, -0.5, 0.5, 1.5), opacity 0.4s ease;
}

#settings-icon:hover,
#toggle-button:hover {
	background-color: rgba(50, 50, 54, 0.85);
	transform: rotate(90deg) scale(1.1);
	transition: all 0.4s cubic-bezier(0.86, 0, 0.07, 1);
}

#settings-icon {
	top: 15px;
	right: 15px;
	z-index: 11;
}

#settings-icon.hidden {
	transform: scale(0);
	opacity: 0;
	pointer-events: none;
}

#settings-icon svg {
	width: 100%;
	height: 100%;
	fill: #f0f0f0;
}

#ui-container {
	position: fixed;
	z-index: 10;
	background-color: rgba(28, 28, 30, 0.85);
	backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 12px;
	color: #f0f0f0;
	padding: 10px;
	max-height: calc(100vh - 30px);
	display: flex;
	flex-direction: column;
	top: 15px;
	right: 15px;
	transform-origin: top right;
	transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease;
}

#ui-container.hidden {
	transform: scale(0);
	opacity: 0;
	pointer-events: none;
}

#ui-container.hiding {
	animation: fly-out 0.4s cubic-bezier(0.5, 0, 0.75, 0) forwards;
}

@keyframes fly-out {
	from {
		transform: var(--current-transform);
		opacity: 1;
	}
	to {
		transform: translate(var(--end-tx), var(--end-ty)) scale(0);
		opacity: 0;
	}
}

#ui-container .header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 10px 10px 10px;
	font-weight: bold;
	font-size: 1.1em;
	user-select: none;
	cursor: grab;
}

#ui-container .header:active {
	cursor: grabbing;
}

#toggle-button {
	position: static;
	color: #f0f0f0;
}

#periodic-table {
	display: grid;
	grid-template-columns: repeat(18, 34px);
	grid-template-rows: repeat(4, 34px);
	gap: 2px;
	overflow-y: auto;
	padding: 2px;
}

.element {
	transform: scale(1);
	width: 34px;
	height: 34px;
	border: 1px solid #555;
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	font-weight: bold;
	font-size: 12px;
	cursor: pointer;
	transition: background-color 0.2s, border-color 0.2s, transform 0.4s ease-out, opacity 0.3s ease;
	user-select: none;
	border-radius: 4px;
	position: relative;
}

.element .number {
	transform: scale(0.75);
	font-weight: normal;
	position: absolute;
	top: 0px;
	left: 1px;
	color: #aaa;
}

.element:hover {
	transform: scale(1.1);
	background-color: #4a4a4a;
	border-color: #aaa;
}

.element.disabled {
	opacity: 0.4;
	cursor: not-allowed;
	pointer-events: none;
}

.element.disabled:hover {
	transform: none;
	background-color: transparent;
	border-color: #555;
}

.controls-info {
	padding: 15px 10px 5px 10px;
	font-size: 0.8em;
	color: #ccc;
}

.controls-info p {
	margin-bottom: 8px;
}

#reset-button {
	width: 100%;
	padding: 8px;
	background-color: #c0392b;
	border: none;
	color: white;
	border-radius: 5px;
	cursor: pointer;
	font-weight: bold;
	transition: background-color 0.2s;
}

#reset-button:hover {
	background-color: #e74c3c;
	transform: scale(1.01);
	transition: all 0.4s cubic-bezier(0.86, 0, 0.07, 1);
}

#molecule-info {
	position: absolute;
	top: 20px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 5;
	color: #f0f0f0;
	text-align: center;
	pointer-events: none;
	text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
	transition: opacity 0.3s ease;
	opacity: 0;
}

#molecule-info.visible {
	opacity: 1;
}

#molecule-formula {
	font-size: 2.2em;
	font-weight: bold;
	margin: 0;
}

#molecule-name {
	font-size: 1.2em;
	margin: 5px 0 0 0;
	font-style: italic;
}

#resize-handle {
	position: absolute;
	bottom: 5px;
	left: 5px;
	width: 15px;
	height: 15px;
	cursor: sw-resize;
	z-index: 12;
	opacity: 0.7;
	background-image:
		linear-gradient(135deg, transparent 45%, #aaa 45%, #aaa 55%, transparent 55%),
		linear-gradient(135deg, transparent 65%, #aaa 65%, #aaa 75%, transparent 75%);
	transform: rotate(90deg);
	background-repeat: no-repeat;
	background-position: bottom left;
}

#resize-handle:hover {
	bottom: 4px;
	right: 4px;
	opacity: 1;
	background-image:
		linear-gradient(135deg, transparent 45%, #aaa 45%, #aaa 50%, transparent 45%),
		linear-gradient(135deg, transparent 70%, #aaa 65%, #aaa 75%, transparent 65%);
	transition: all 0.4s ease-out;
}

#formula-input {
	width: 100%;
	padding: 8px;
	margin-bottom: 10px;
	background-color: rgba(0, 0, 0, 0.3);
	border: 1px solid #555;
	color: #f0f0f0;
	border-radius: 5px;
	font-size: 1em;
	font-family: monospace;
	transition: border-color 0.2s;
}

#formula-input:focus {
	outline: none;
	border-color: #aaa;
}

#formula-input.error {
	border-color: #c0392b;
}