/* --- 全局重置与字体 --- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
transition: background-color 0.4s ease, color 0.4s ease;
overflow: hidden; /* 防止滚动条出现 */
}
/* --- 主题颜色变量 --- */
:root {
/* 亮色主题 */
--bg-color-light: #e0e5ec;
--text-color-light: #5c677d;
--primary-color-light: #4a72ff;
--light-shadow-light: #ffffff;
--dark-shadow-light: #a3b1c6;
/* 暗色主题 */
--bg-color-dark: #2c3038;
--text-color-dark: #b0b8c9;
--primary-color-dark: #4a72ff;
--light-shadow-dark: #3a3e47;
--dark-shadow-dark: #1e2127;
}
/* --- 主题应用 --- */
body {
background-color: var(--bg-color-light);
color: var(--text-color-light);
}
body.dark-mode {
background-color: var(--bg-color-dark);
color: var(--text-color-dark);
}
/* --- 背景效果 --- */
.fluid-background {
position: fixed;
top: 50%;
left: 50%;
width: 150vmax;
height: 150vmax;
background: linear-gradient(45deg, var(--primary-color-light), #9198e5);
border-radius: 45% 55% 70% 30% / 30% 50% 50% 70%;
transform: translate(-50%, -50%);
animation: fluid-rotate 15s linear infinite;
filter: blur(120px);
opacity: 0.5;
z-index: -2;
}
body.dark-mode .fluid-background {
background: linear-gradient(45deg, var(--primary-color-dark), #1f2c58);
}
@keyframes fluid-rotate {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
#particle-canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
/* --- 整体布局 --- */
.container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
/* --- 登录框样式 --- */
.login-box {
width: 100%;
max-width: 400px;
padding: 40px;
border-radius: 20px;
background-color: var(--bg-color-light);
box-shadow: 12px 12px 24px var(--dark-shadow-light), -12px -12px 24px var(--light-shadow-light);
transition: all 0.4s ease;
text-align: center;
}
body.dark-mode .login-box {
background-color: var(--bg-color-dark);
box-shadow: 12px 12px 24px var(--dark-shadow-dark), -12px -12px 24px var(--light-shadow-dark);
}
.login-box h2 {
font-weight: 600;
font-size: 2rem;
margin-bottom: 10px;
}
.login-box > p {
margin-bottom: 30px;
font-size: 0.9rem;
opacity: 0.8;
}
/* --- 表单元素 --- */
.input-group {
margin-bottom: 20px;
text-align: left;
}
.input-group label {
display: block;
margin-bottom: 8px;
font-size: 0.9rem;
font-weight: 500;
}
.input-group input {
width: 100%;
padding: 15px;
border: none;
border-radius: 10px;
outline: none;
font-size: 1rem;
background-color: var(--bg-color-light);
color: var(--text-color-light);
/* 初始凹陷效果 */
box-shadow: inset 5px 5px 10px var(--dark-shadow-light), inset -5px -5px 10px var(--light-shadow-light);
transition: all 0.3s ease;
}
body.dark-mode .input-group input {
background-color: var(--bg-color-dark);
color: var(--text-color-dark);
box-shadow: inset 5px 5px 10px var(--dark-shadow-dark), inset -5px -5px 10px var(--light-shadow-dark);
}
/* 输入框聚焦时的微交互 */
.input-group input:focus {
box-shadow: inset 7px 7px 14px var(--dark-shadow-light), inset -7px -7px 14px var(--light-shadow-light);
}
body.dark-mode .input-group input:focus {
box-shadow: inset 7px 7px 14px var(--dark-shadow-dark), inset -7px -7px 14px var(--light-shadow-dark);
}
/* --- 表单选项 --- */
.options {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25px;
font-size: 0.85rem;
}
.remember-me {
display: flex;
align-items: center;
}
.remember-me input[type="checkbox"] {
display: none; /* 隐藏原生 checkbox */
}
.remember-me label {
position: relative;
padding-left: 25px;
cursor: pointer;
user-select: none;
}
/* 自定义 checkbox 样式 */
.remember-me label::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 16px;
height: 16px;
border-radius: 4px;
background: var(--bg-color-light);
box-shadow: inset 2px 2px 4px var(--dark-shadow-light), inset -2px -2px 4px var(--light-shadow-light);
transition: all 0.3s ease;
}
body.dark-mode .remember-me label::before {
background: var(--bg-color-dark);
box-shadow: inset 2px 2px 4px var(--dark-shadow-dark), inset -2px -2px 4px var(--light-shadow-dark);
}
.remember-me input[type="checkbox"]:checked + label::after {
content: '✔';
position: absolute;
left: 2px;
top: 50%;
transform: translateY(-50%);
font-size: 12px;
color: var(--primary-color-light);
}
body.dark-mode .remember-me input[type="checkbox"]:checked + label::after {
color: var(--primary-color-dark);
}
.options a {
color: var(--text-color-light);
text-decoration: none;
transition: color 0.3s ease;
}
body.dark-mode .options a {
color: var(--text-color-dark);
}
.options a:hover {
color: var(--primary-color-light);
}
body.dark-mode .options a:hover {
color: var(--primary-color-dark);
}
/* --- 登录按钮 --- */
.btn-login {
width: 100%;
padding: 15px;
border: none;
border-radius: 10px;
background-color: var(--primary-color-light);
color: white;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
box-shadow: 6px 6px 12px var(--dark-shadow-light), -6px -6px 12px var(--light-shadow-light);
transition: all 0.3s ease;
}
body.dark-mode .btn-login {
background-color: var(--primary-color-dark);
box-shadow: 6px 6px 12px var(--dark-shadow-dark), -6px -6px 12px var(--light-shadow-dark);
}
/* 按钮按下的微交互 */
.btn-login:active {
box-shadow: inset 4px 4px 8px #3a5cc8, inset -4px -4px 8px #5a88ff;
transform: translateY(2px);
}
body.dark-mode .btn-login:active {
box-shadow: inset 4px 4px 8px #3a5cc8, inset -4px -4px 8px #5a88ff;
}
/* --- 分隔线 --- */
.separator {
margin: 30px 0;
display: flex;
align-items: center;
text-align: center;
font-size: 0.8rem;
opacity: 0.7;
}
.separator::before, .separator::after {
content: '';
flex: 1;
height: 1px;
background-color: var(--dark-shadow-light);
opacity: 0.5;
}
body.dark-mode .separator::before, body.dark-mode .separator::after {
background-color: var(--light-shadow-dark);
}
.separator span {
padding: 0 15px;
}
/* --- 社交登录 --- */
.social-login {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 25px;
}
.social-icon {
width: 50px;
height: 50px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5rem;
font-weight: bold;
text-decoration: none;
color: var(--text-color-light);
background-color: var(--bg-color-light);
box-shadow: 5px 5px 10px var(--dark-shadow-light), -5px -5px 10px var(--light-shadow-light);
transition: all 0.3s ease;
}
body.dark-mode .social-icon {
color: var(--text-color-dark);
background-color: var(--bg-color-dark);
box-shadow: 5px 5px 10px var(--dark-shadow-dark), -5px -5px 10px var(--light-shadow-dark);
}
.social-icon:active {
box-shadow: inset 3px 3px 6px var(--dark-shadow-light), inset -3px -3px 6px var(--light-shadow-light);
}
body.dark-mode .social-icon:active {
box-shadow: inset 3px 3px 6px var(--dark-shadow-dark), inset -3px -3px 6px var(--light-shadow-dark);
}
/* --- 注册链接 --- */
.signup-link {
font-size: 0.9rem;
}
.signup-link a {
color: var(--primary-color-light);
font-weight: 500;
text-decoration: none;
}
body.dark-mode .signup-link a {
color: var(--primary-color-dark);
}
/* --- 主题切换器 --- */
.theme-switcher {
position: fixed;
top: 30px;
right: 30px;
width: 60px;
height: 30px;
border-radius: 15px;
cursor: pointer;
background-color: var(--bg-color-light);
box-shadow: 5px 5px 10px var(--dark-shadow-light), -5px -5px 10px var(--light-shadow-light);
transition: all 0.4s ease;
z-index: 100;
}
body.dark-mode .theme-switcher {
background-color: var(--bg-color-dark);
box-shadow: 5px 5px 10px var(--dark-shadow-dark), -5px -5px 10px var(--light-shadow-dark);
}
.switcher-thumb {
position: absolute;
top: 3px;
left: 3px;
width: 24px;
height: 24px;
border-radius: 50%;
background-color: var(--primary-color-light);
transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
body.dark-mode .switcher-thumb {
transform: translateX(30px);
background-color: var(--primary-color-dark);
}
// --- 主题切换 ---
const themeSwitcher = document.querySelector('.theme-switcher');
const body = document.body;
themeSwitcher.addEventListener('click', () => {
body.classList.toggle('dark-mode');
});
// --- 粒子背景效果 ---
const canvas = document.getElementById('particle-canvas');
const ctx = canvas.getContext('2d');
let particlesArray;
// 设置 canvas 尺寸
function setCanvasSize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
setCanvasSize();
// 粒子类
class Particle {
constructor(x, y, directionX, directionY, size, color) {
this.x = x;
this.y = y;
this.directionX = directionX;
this.directionY = directionY;
this.size = size;
this.color = color;
}
// 绘制单个粒子
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
ctx.fillStyle = this.color;
ctx.fill();
}
// 更新粒子位置
update() {
if (this.x > canvas.width || this.x < 0) {
this.directionX = -this.directionX;
}
if (this.y > canvas.height || this.y < 0) {
this.directionY = -this.directionY;
}
this.x += this.directionX;
this.y += this.directionY;
this.draw();
}
}
// 创建粒子数组
function init() {
particlesArray = [];
const isDarkMode = body.classList.contains('dark-mode');
const particleColor = isDarkMode ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.15)';
const numberOfParticles = (canvas.height * canvas.width) / 9000;
for (let i = 0; i < numberOfParticles; i++) {
const size = (Math.random() * 2) + 1;
const x = (Math.random() * ((innerWidth - size * 2) - (size * 2)) + size * 2);
const y = (Math.random() * ((innerHeight - size * 2) - (size * 2)) + size * 2);
const directionX = (Math.random() * 0.4) - 0.2;
const directionY = (Math.random() * 0.4) - 0.2;
particlesArray.push(new Particle(x, y, directionX, directionY, size, particleColor));
}
}
// 动画循环
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, innerWidth, innerHeight);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update();
}
connect();
}
// 连接粒子
function connect() {
let opacityValue = 1;
for (let a = 0; a < particlesArray.length; a++) {
for (let b = a; b < particlesArray.length; b++) {
const distance = ((particlesArray[a].x - particlesArray[b].x) * (particlesArray[a].x - particlesArray[b].x)) +
((particlesArray[a].y - particlesArray[b].y) * (particlesArray[a].y - particlesArray[b].y));
if (distance < (canvas.width / 7) * (canvas.height / 7)) {
opacityValue = 1 - (distance / 20000);
const isDarkMode = body.classList.contains('dark-mode');
const lineColor = isDarkMode ? `rgba(255, 255, 255, ${opacityValue * 0.2})` : `rgba(0, 0, 0, ${opacityValue * 0.2})`;
ctx.strokeStyle = lineColor;
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(particlesArray[a].x, particlesArray[a].y);
ctx.lineTo(particlesArray[b].x, particlesArray[b].y);
ctx.stroke();
}
}
}
}
// 事件监听器
window.addEventListener('resize', () => {
setCanvasSize();
init();
});
// 主题切换时重新初始化粒子颜色
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.attributeName === "class") {
init();
}
});
});
observer.observe(body, { attributes: true });
// 启动
init();
animate();