/*
 * 高级视觉增强 - 专业级优化
 * 微交互、动画、性能优化
 */

/* ========================================
   CSS变量 - 动态主题系统
   ======================================== */

:root {
    /* 动画时长 */
    --transition-fast: 0.15s;
    --transition-base: 0.3s;
    --transition-slow: 0.5s;
    
    /* 缓动函数 */
    --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-in-out-circ: cubic-bezier(0.85, 0, 0.15, 1);
    
    /* 阴影层次 */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.20);
    
    /* 模糊效果 */
    --blur-sm: blur(4px);
    --blur-md: blur(8px);
    --blur-lg: blur(16px);
}

/* ========================================
   性能优化 - GPU加速
   ======================================== */

/* 强制GPU加速的元素 */
.wp-block-image img,
.wp-block-post-featured-image img,
.wp-block-button__link,
.wp-block-group,
#header,
#footer {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 优化渲染性能 */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* 平滑滚动 */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   加载动画 - 骨架屏
   ======================================== */

/* 图片加载占位 */
img:not([src]),
img[src=""] {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* 内容加载状态 */
.loading-skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

/* ========================================
   微交互 - 按钮增强
   ======================================== */

.wp-block-button__link,
.wp-element-button {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

/* 按钮波纹效果 */
.wp-block-button__link::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.wp-block-button__link:active::before {
    width: 300px;
    height: 300px;
}

/* 按钮光泽效果 */
.wp-block-button__link::after {
    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: translateX(-100%);
    transition: transform 0.6s;
}

.wp-block-button__link:hover::after {
    transform: translateX(100%);
}

/* ========================================
   卡片悬停效果 - 3D变换
   ======================================== */

@media (min-width: 769px) {
    .wp-block-group,
    .wp-block-post {
        transition: all var(--transition-base) var(--ease-out-expo);
    }
    
    .wp-block-group:hover,
    .wp-block-post:hover {
        transform: translateY(-8px) scale(1.02);
        box-shadow: var(--shadow-xl);
    }
    
    /* 卡片内图片视差效果 */
    .wp-block-group:hover img {
        transform: scale(1.05);
    }
}

/* ========================================
   图片优化 - 平滑加载（无闪烁）
   ======================================== */

/* 图片默认可见，避免闪烁 */
img {
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* 懒加载图片淡入 */
img[loading="lazy"]:not(.loaded) {
    opacity: 0.3;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* 图片模糊到清晰（仅用于data-src） */
img[data-src]:not(.loaded) {
    filter: blur(10px);
    transition: filter 0.4s;
}

img[data-src].loaded {
    filter: blur(0);
}

/* ========================================
   滚动动画 - 安全版（不影响首屏）
   ======================================== */

/* 只有明确添加动画类的元素才会有初始隐藏状态 */
.fade-in-animation:not(.visible) {
    opacity: 0;
    transform: translateY(30px);
}

.fade-in-animation {
    transition: opacity 0.6s var(--ease-out-expo),
                transform 0.6s var(--ease-out-expo);
}

.fade-in-animation.visible {
    opacity: 1;
    transform: translateY(0);
}

/* 从左滑入 */
.slide-in-left-animation:not(.visible) {
    opacity: 0;
    transform: translateX(-50px);
}

.slide-in-left-animation {
    transition: opacity 0.6s var(--ease-out-expo),
                transform 0.6s var(--ease-out-expo);
}

.slide-in-left-animation.visible {
    opacity: 1;
    transform: translateX(0);
}

/* 从右滑入 */
.slide-in-right-animation:not(.visible) {
    opacity: 0;
    transform: translateX(50px);
}

.slide-in-right-animation {
    transition: opacity 0.6s var(--ease-out-expo),
                transform 0.6s var(--ease-out-expo);
}

.slide-in-right-animation.visible {
    opacity: 1;
    transform: translateX(0);
}

/* 缩放进入 */
.scale-in-animation:not(.visible) {
    opacity: 0;
    transform: scale(0.9);
}

.scale-in-animation {
    transition: opacity 0.6s var(--ease-out-back),
                transform 0.6s var(--ease-out-back);
}

.scale-in-animation.visible {
    opacity: 1;
    transform: scale(1);
}

/* ========================================
   导航栏 - 滚动效果
   ======================================== */

#header {
    transition: all var(--transition-base) var(--ease-out-expo);
}

/* 滚动后导航栏变化 */
#header.scrolled {
    box-shadow: var(--shadow-md);
    backdrop-filter: var(--blur-md);
    background: rgba(255, 255, 255, 0.95);
}

@media (max-width: 768px) {
    #header.scrolled {
        padding: 12px 20px !important;
    }
}

/* ========================================
   返回顶部按钮 - 增强版
   ======================================== */

.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #024caa 0%, #091057 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: var(--shadow-lg);
    z-index: 999;
    border: none;
    cursor: pointer;
    opacity: 0;
    transform: translateY(20px) scale(0.8);
    transition: all var(--transition-base) var(--ease-out-back);
    pointer-events: none;
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.back-to-top:hover {
    transform: translateY(-4px) scale(1.1);
    box-shadow: var(--shadow-xl);
}

.back-to-top:active {
    transform: translateY(-2px) scale(1.05);
}

@media (max-width: 768px) {
    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
}

/* ========================================
   文字选择美化
   ======================================== */

::selection {
    background: rgba(2, 76, 170, 0.2);
    color: #091057;
}

::-moz-selection {
    background: rgba(2, 76, 170, 0.2);
    color: #091057;
}

/* ========================================
   滚动条美化
   ======================================== */

/* Webkit浏览器 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #024caa 0%, #091057 100%);
    border-radius: 5px;
    transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #024caa #f1f1f1;
}

/* ========================================
   焦点状态优化
   ======================================== */

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(2, 76, 170, 0.5);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ========================================
   加载进度条
   ======================================== */

.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #024caa 0%, #f59e0b 100%);
    z-index: 9999;
    transition: width 0.3s var(--ease-out-expo);
    box-shadow: 0 0 10px rgba(2, 76, 170, 0.5);
}

.loading-bar.loading {
    animation: loading-progress 2s ease-in-out infinite;
}

@keyframes loading-progress {
    0% {
        width: 0;
    }
    50% {
        width: 70%;
    }
    100% {
        width: 100%;
    }
}

/* ========================================
   图片画廊优化
   ======================================== */

.wp-block-gallery {
    gap: 16px;
}

.wp-block-gallery img {
    transition: all var(--transition-base) var(--ease-out-expo);
}

.wp-block-gallery img:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
    z-index: 1;
}

/* ========================================
   表单增强
   ======================================== */

input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
    transition: all var(--transition-base) var(--ease-out-expo);
}

input:focus,
textarea:focus,
select:focus {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* 输入验证状态 */
input:valid {
    border-color: #10b981;
}

input:invalid:not(:placeholder-shown) {
    border-color: #ef4444;
}

/* ========================================
   工具提示
   ======================================== */

[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 13px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base), transform var(--transition-base);
    z-index: 1000;
}

[data-tooltip]::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
    opacity: 1;
}

[data-tooltip]:hover::before {
    transform: translateX(-50%) translateY(-12px);
}

/* ========================================
   徽章和标签
   ======================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 20px;
    background: linear-gradient(135deg, #024caa 0%, #091057 100%);
    color: white;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}

.badge:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ========================================
   分隔线美化
   ======================================== */

hr,
.wp-block-separator {
    border: none;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(2, 76, 170, 0.3) 50%,
        transparent 100%
    );
    margin: 40px 0;
}

/* ========================================
   引用块美化
   ======================================== */

blockquote,
.wp-block-quote {
    position: relative;
    padding: 24px 24px 24px 60px;
    background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
    border-left: 4px solid #024caa;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    font-style: italic;
    color: #4a4a4a;
}

blockquote::before {
    content: '"';
    position: absolute;
    left: 20px;
    top: 10px;
    font-size: 48px;
    color: rgba(2, 76, 170, 0.2);
    font-family: Georgia, serif;
    line-height: 1;
}

/* ========================================
   代码块美化
   ======================================== */

code,
pre {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
}

code {
    padding: 2px 6px;
    font-size: 0.9em;
}

pre {
    padding: 20px;
    overflow-x: auto;
    box-shadow: var(--shadow-md);
}

pre code {
    background: none;
    padding: 0;
}

/* ========================================
   通知/警告框
   ======================================== */

.notice {
    padding: 16px 20px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid;
    box-shadow: var(--shadow-sm);
}

.notice-info {
    background: #e0f2fe;
    border-color: #0284c7;
    color: #075985;
}

.notice-success {
    background: #d1fae5;
    border-color: #10b981;
    color: #065f46;
}

.notice-warning {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
}

.notice-error {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

/* ========================================
   打印样式优化
   ======================================== */

@media print {
    *,
    *::before,
    *::after {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a,
    a:visited {
        text-decoration: underline;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    p {
        orphans: 3;
        widows: 3;
    }
}

/* ========================================
   暗色模式支持（可选）
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* 如果需要暗色模式，可以在这里添加样式 */
    /* 目前保持浅色主题 */
}

/* ========================================
   高对比度模式支持
   ======================================== */

@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
    }
    
    a {
        text-decoration: underline;
    }
}
