* {
	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;
	animation: fadeIn 0.5s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

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

@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

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

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

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

#settings-icon,
#toggle-button,
#info-button,
#info-close-button,
#fullscreen-button,
#tools-icon,
#tools-close-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;
	animation: fadeIn 1.3s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

#settings-icon:hover,
#toggle-button:hover,
#info-button:hover,
#info-close-button:hover,
#fullscreen-button:hover,
#tools-icon:hover,
#tools-close-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.hidden,
#info-button.hidden,
#tools-icon.hidden {
	transform: scale(0);
	opacity: 0;
	pointer-events: none;
}

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

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

#info-button {
	top: 15px;
	left: 15px;
	z-index: 11;
}

#fullscreen-button {
	bottom: 15px;
	right: 15px;
	z-index: 11;
}

#tools-icon {
	bottom: 15px;
	left: 15px;
	z-index: 11;
}

#ui-container,
#info-ui-container,
#tools-ui-container {
	position: fixed;
	z-index: 12;
	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;
	transition: opacity 0.3s ease, filter 0.3s ease;
}

#ui-container {
	transform-origin: top right;
	top: 15px;
	right: 15px;
}

#info-ui-container {
	top: 15px;
	left: 15px;
	right: auto;
	transform-origin: top left;
}

#tools-ui-container {
	bottom: 15px;
	left: 15px;
	transform-origin: bottom left;
}

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

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

#ui-container.showing,
#info-ui-container.showing,
#tools-ui-container.showing {
	animation: fly-in 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

#ui-container .header,
#info-ui-container .header,
#tools-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;
	animation: fadeIn 1.4s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

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

#toggle-button,
#info-close-button,
#tools-close-button {
	position: static;
	color: #f0f0f0;
	animation: none;
}

#info-content-area {
	padding: 0 10px 10px;
	overflow-y: auto;
}

#info-content-area h4 {
	margin-top: 10px;
	margin-bottom: 5px;
	border-bottom: 1px solid #555;
	padding-bottom: 3px;
}

#info-content-area ul {
	list-style-position: inside;
	padding-left: 5px;
}

#info-content-area li {
	margin-bottom: 3px;
	font-size: 0.9em;
}

#periodic-table {
	display: grid;
	grid-template-columns: repeat(18, 34px);
	grid-template-rows: repeat(4, 34px);
	gap: 2px;
	overflow-y: auto;
	padding: 2px;
	animation: fadeIn 1.5s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

.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;
	animation: fadeIn 1.5s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

#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;
	animation: fadeIn 1.5s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

#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;
	left: 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;
	animation: fadeIn 1.5s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

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

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

#tools-content-area {
	padding: 10px;
	overflow-y: auto;
}

#vdw-controls-container,
#formal-charge-controls-container,
#lone-pair-controls-container {
	padding: 10px;
	border: 1px solid #444;
	border-radius: 8px;
	margin-bottom: 10px;
}

#vdw-controls-container h4,
#formal-charge-controls-container h4,
#lone-pair-controls-container h4 {
	margin-top: 0;
	margin-bottom: 10px;
	font-size: 1em;
	border-bottom: 1px solid #555;
	padding-bottom: 5px;
}

.tool-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 8px;
}

.tool-row:last-child {
	margin-bottom: 0;
}

.tool-row.hidden {
	display: none;
}

.tool-row label {
	font-size: 0.9em;
}

input[type="range"] {
	-webkit-appearance: none;
	appearance: none;
	height: 8px;
	background: #444;
	border-radius: 5px;
	outline: none;
	opacity: 0.7;
	transition: opacity .2s;
}

input[type="range"]:hover {
	opacity: 1;
}

input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 16px;
	height: 16px;
	background: #f0f0f0;
	cursor: pointer;
	border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
	width: 16px;
	height: 16px;
	background: #f0f0f0;
	cursor: pointer;
	border-radius: 50%;
}

input[type="checkbox"] {
	-webkit-appearance: none;
	appearance: none;
	background-color: #444;
	margin: 0;
	font: inherit;
	color: currentColor;
	width: 1.15em;
	height: 1.15em;
	border-radius: 0.25em;
	transform: translateY(-0.075em);
	display: grid;
	place-content: center;
	cursor: pointer;
}

input[type="checkbox"]::before {
	content: "";
	width: 0.65em;
	height: 0.65em;
	transform: scale(0);
	transition: 120ms transform ease-in-out;
	box-shadow: inset 1em 1em #f0f0f0;
	transform-origin: bottom left;
	clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

input[type="checkbox"]:checked::before {
	transform: scale(1);
}

.slider-with-value {
	position: relative;
	display: flex;
	align-items: left;
	padding-left: 10px;
}

.slider-with-value input[type="range"] {
	flex-grow: 1;
}

.slider-with-value span {
	width: 3.5em;
	text-align: right;
	font-size: 0.9em;
	padding-left: 10px;
	color: #ccc;
	font-variant-numeric: tabular-nums;
}

.slider-tooltip {
	position: absolute;
	background-color: #333;
	color: #fff;
	padding: 4px 8px;
	border-radius: 4px;
	font-size: 0.8em;
	pointer-events: none;
	transform: translate(-50%, -40px);
	top: 100%;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s, visibility 0.2s;
	z-index: 10;
}

.slider-tooltip.visible {
	opacity: 1;
	visibility: visible;
}

.snap-guide {
	position: fixed;
	background-color: rgba(150, 150, 1, 0.1);
	z-index: 9999;
	display: none;
	pointer-events: none;
}

.snap-guide.vertical {
	width: 1x;
	height: 100%;
	top: 0;
}

.snap-guide.horizontal {
	height: 1px;
	width: 100%;
	left: 0;
}

.panel-out-of-focus {
	opacity: 0.8 !important;
	filter: brightness(0.8);
}

.is-dragging {
	opacity: 0.9 !important;
	transition: opacity 0.2s ease;
}

footer {
	position: fixed;
	bottom: 10px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 10;
	color: #999;
	font-size: 0.75rem;
	text-align: center;
	pointer-events: none;
	text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
	white-space: nowrap;
	animation: fadeIn 1s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

footer a {
	color: #bbb;
	text-decoration: none;
	pointer-events: auto;
	transition: color 0.2s;
	animation: fadeIn 1.1s cubic-bezier(0.5, -0.5, 0.5, 1.5);
}

footer a:hover {
	color: #fff;
	text-decoration: underline;
}
	
@media (max-width: 768px) {
	#settings-icon,
	#toggle-button,
	#info-button,
	#info-close-button,
	#fullscreen-button,
	#tools-icon,
	#tools-close-button {
		width: 48px;
		height: 48px;
		padding: 12px;
	}
	#settings-icon {
		top: 10px;
		right: 10px;
	}
	#info-button {
		top: 10px;
		left: 10px;
	}
	#fullscreen-button {
		bottom: 10px;
		right: 10px;
	}
	#tools-icon {
		bottom: 10px;
		left: 10px;
	}
	#resize-handle {
		display: none;
	}
	#ui-container,
	#info-ui-container,
	#tools-ui-container {
		width: auto;
		left: 10px;
		right: 10px;
		max-height: calc(100vh - 20px);
	}
	#ui-container {
		top: 10px;
		bottom: auto;
		transform-origin: top center;
	}
	#info-ui-container {
		top: 10px;
		bottom: auto;
		transform-origin: top center;
	}
	#tools-ui-container {
		top: auto;
		bottom: 10px;
		transform-origin: bottom center;
	}
	#resize-handle {
		display: none;
	}
	#periodic-table {
		grid-template-columns: repeat(18, 28px);
		grid-template-rows: repeat(4, 28px);
		overflow-x: auto;
	}
	.element {
		width: 28px;
		height: 28px;
		font-size: 10px;
	}
	.element .number {
		transform: scale(0.7);
	}
	#molecule-info {
		top: 15px;
	}
	#molecule-formula {
		font-size: 1.8em;
	}
	#molecule-name {
		font-size: 1.0em;
	}
	#info-content-area li {
		font-size: 0.9em;
		margin-bottom: 5px;
	}
	#formula-input,
	#reset-button {
		padding: 12px;
		font-size: 1em;
	}
	#tools-content-area {
		padding-bottom: 10px;
	}
	footer {
		bottom: 5px;
		font-size: 0.65rem;
	}
}