/**
 * SAM Web Editor - 增强视觉效果和动画
 * 包含：粒子效果、渐变流动、光标轨迹、高级交互
 */

/* ========== 粒子背景 Canvas ========== */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    opacity: 0.4;
}

/* ========== 光标轨迹 Canvas ========== */
#cursor-trail {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* ========== 渐变流动背景 ========== */
.gradient-flow-bg {
    background: linear-gradient(-45deg, 
        #1c1c1e, 
        #2c2c2e, 
        #1a1a2e, 
        #16213e,
        #0f172a
    );
    background-size: 400% 400%;
    animation: gradientFlow 15s ease infinite;
}

@keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ========== 网格背景效果 ========== */
.grid-bg {
    background-image: 
        linear-gradient(rgba(0, 122, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 122, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: gridPulse 4s ease-in-out infinite;
}

@keyframes gridPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

/* ========== 噪点纹理叠加 ========== */
.noise-overlay {
    position: relative;
}

.noise-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    opacity: 0.03;
    pointer-events: none;
    z-index: 1;
}

/* ========== 高级按钮效果 ========== */

/* 霓虹按钮 */
.btn-neon {
    position: relative;
    background: transparent;
    border: 2px solid var(--accent-blue);
    color: var(--accent-blue);
    overflow: hidden;
    transition: all 0.3s ease;
}

.btn-neon::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 122, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn-neon:hover::before {
    left: 100%;
}

.btn-neon:hover {
    box-shadow: 0 0 20px rgba(0, 122, 255, 0.5), inset 0 0 20px rgba(0, 122, 255, 0.2);
    text-shadow: 0 0 5px var(--accent-blue);
}

/* 填充动画按钮 */
.btn-fill {
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.btn-fill::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: var(--accent-blue);
    z-index: -1;
    transition: width 0.3s ease;
}

.btn-fill:hover::before {
    width: 100%;
}

.btn-fill:hover {
    color: white;
}

/* 边框流动动画按钮 */
.btn-border-flow {
    position: relative;
    background: transparent;
    border: none;
    z-index: 1;
}

.btn-border-flow::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-md);
    padding: 2px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple), var(--accent-teal), var(--accent-blue));
    background-size: 300% 100%;
    -webkit-mask: 
        linear-gradient(#fff 0 0) content-box, 
        linear-gradient(#fff 0 0);
    mask: 
        linear-gradient(#fff 0 0) content-box, 
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: borderFlow 3s linear infinite;
}

@keyframes borderFlow {
    0% { background-position: 0% 50%; }
    100% { background-position: 300% 50%; }
}

/* ========== 高级卡片效果 ========== */

/* 全息卡片 */
.card-holographic {
    position: relative;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
}

.card-holographic::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255,255,255,0.1) 50%,
        transparent 70%
    );
    transform: rotate(45deg);
    transition: all 0.5s ease;
    opacity: 0;
}

.card-holographic:hover::before {
    animation: holographicShine 0.8s ease;
}

@keyframes holographicShine {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); opacity: 0; }
}

/* 3D 翻转卡片 */
.card-flip {
    perspective: 1000px;
    transform-style: preserve-3d;
}

.card-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.card-flip:hover .card-flip-inner {
    transform: rotateY(180deg);
}

.card-flip-front, .card-flip-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-flip-back {
    transform: rotateY(180deg);
}

/* 堆叠卡片效果 */
.card-stack {
    position: relative;
}

.card-stack::before,
.card-stack::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: inherit;
    border-radius: inherit;
    z-index: -1;
    transition: all 0.3s ease;
}

.card-stack::before {
    transform: translateY(10px) scale(0.95);
    opacity: 0.5;
}

.card-stack::after {
    transform: translateY(20px) scale(0.9);
    opacity: 0.3;
}

.card-stack:hover::before {
    transform: translateY(15px) scale(0.95);
}

.card-stack:hover::after {
    transform: translateY(30px) scale(0.9);
}

/* ========== 文字效果 ========== */

/* 故障文字效果 */
.text-glitch {
    position: relative;
    color: var(--text-primary);
}

.text-glitch::before,
.text-glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.text-glitch::before {
    color: #ff0000;
    animation: glitch-1 0.3s infinite linear alternate-reverse;
    clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%);
}

.text-glitch::after {
    color: #00ffff;
    animation: glitch-2 0.3s infinite linear alternate-reverse;
    clip-path: polygon(0 65%, 100% 65%, 100% 100%, 0 100%);
}

@keyframes glitch-1 {
    0% { transform: translateX(0); }
    20% { transform: translateX(-2px); }
    40% { transform: translateX(2px); }
    60% { transform: translateX(-1px); }
    80% { transform: translateX(1px); }
    100% { transform: translateX(0); }
}

@keyframes glitch-2 {
    0% { transform: translateX(0); }
    20% { transform: translateX(2px); }
    40% { transform: translateX(-2px); }
    60% { transform: translateX(1px); }
    80% { transform: translateX(-1px); }
    100% { transform: translateX(0); }
}

/* 液体填充文字 */
.text-liquid-fill {
    position: relative;
    background: linear-gradient(var(--accent-blue) 0%, var(--accent-blue) 100%);
    background-size: 100% 0;
    background-repeat: no-repeat;
    -webkit-background-clip: text;
    background-clip: text;
    transition: background-size 0.5s ease;
}

.text-liquid-fill:hover {
    background-size: 100% 100%;
}

/* 打字机效果 */
.text-typewriter {
    overflow: hidden;
    border-right: 2px solid var(--accent-blue);
    white-space: nowrap;
    animation: typing 3.5s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: var(--accent-blue); }
}

/* ========== 加载动画 ========== */

/* 脉冲圆环 */
.loader-pulse-rings {
    position: relative;
    width: 60px;
    height: 60px;
}

.loader-pulse-rings::before,
.loader-pulse-rings::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    border: 3px solid var(--accent-blue);
    animation: pulse-ring 1.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

.loader-pulse-rings::after {
    animation-delay: 0.5s;
}

@keyframes pulse-ring {
    0% {
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    100% {
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        opacity: 0;
    }
}

/* 弹跳点 */
.loader-bouncing-dots {
    display: flex;
    gap: 8px;
}

.loader-bouncing-dots div {
    width: 12px;
    height: 12px;
    background: var(--accent-blue);
    border-radius: 50%;
    animation: bouncing-dots 1.4s ease-in-out infinite both;
}

.loader-bouncing-dots div:nth-child(1) { animation-delay: -0.32s; }
.loader-bouncing-dots div:nth-child(2) { animation-delay: -0.16s; }

@keyframes bouncing-dots {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* 波浪加载 */
.loader-wave {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 40px;
}

.loader-wave div {
    width: 4px;
    height: 100%;
    background: var(--accent-blue);
    animation: wave 1.2s ease-in-out infinite;
}

.loader-wave div:nth-child(1) { animation-delay: -1.1s; }
.loader-wave div:nth-child(2) { animation-delay: -1.0s; }
.loader-wave div:nth-child(3) { animation-delay: -0.9s; }
.loader-wave div:nth-child(4) { animation-delay: -0.8s; }
.loader-wave div:nth-child(5) { animation-delay: -0.7s; }

@keyframes wave {
    0%, 40%, 100% { transform: scaleY(0.4); }
    20% { transform: scaleY(1); }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--fill-primary);
    border-radius: 4px;
    transition: background 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-blue);
}

/* ========== 焦点效果 ========== */
*:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* ========== 选择文本效果 ========== */
::selection {
    background: rgba(0, 122, 255, 0.3);
    color: var(--text-primary);
}

/* ========== 响应式动画减少 ========== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========== 工具类 ========== */

/* 透视容器 */
.perspective-1000 {
    perspective: 1000px;
}

.perspective-2000 {
    perspective: 2000px;
}

/* 3D 变换样式 */
.preserve-3d {
    transform-style: preserve-3d;
}

.backface-hidden {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* 过渡时间 */
.transition-fast {
    transition-duration: 150ms;
}

.transition-normal {
    transition-duration: 250ms;
}

.transition-slow {
    transition-duration: 350ms;
}

/* 混合模式 */
.blend-multiply {
    mix-blend-mode: multiply;
}

.blend-screen {
    mix-blend-mode: screen;
}

.blend-overlay {
    mix-blend-mode: overlay;
}

/* 滤镜效果 */
.filter-blur-sm {
    filter: blur(4px);
}

.filter-blur-md {
    filter: blur(8px);
}

.filter-blur-lg {
    filter: blur(16px);
}

.filter-grayscale {
    filter: grayscale(100%);
}

.filter-brightness-50 {
    filter: brightness(0.5);
}

.filter-brightness-150 {
    filter: brightness(1.5);
}
