/**
 * H5 主样式文件
 * 微信浏览器优化 + 移动端适配
 */

/* ========== 全局重置 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 禁用iOS长按弹出菜单 */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 允许选择文本内容 */
.article-content,
input,
textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* ========== 字体优化 ========== */
body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "STHeiti", "Microsoft Yahei", Tahoma, Simsun, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== 滚动条优化 ========== */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ========== 图片懒加载占位 ========== */
img.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img.lazy-load.loaded {
    opacity: 1;
}

/* 图片加载失败占位 */
img.error {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    position: relative;
}

img.error::before {
    content: '';
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="gray" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V5a2 2 0 00-2-2H4zm12 12H4l4-8 3 6 2-4 3 6z" clip-rule="evenodd"/></svg>') no-repeat center;
}

/* ========== 按钮点击效果 ========== */
button, a, .clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

button:active, a:active, .clickable:active {
    transform: scale(0.98);
    opacity: 0.8;
}

/* ========== 输入框优化 ========== */
input, textarea {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 8px;
    font-size: 16px; /* 防止iOS自动缩放 */
}

input:focus, textarea:focus {
    outline: none;
}

/* ========== 链接样式 ========== */
a {
    color: inherit;
    text-decoration: none;
}

/* ========== 加载动画 ========== */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========== 骨架屏 ========== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

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

/* ========== 返回顶部按钮动画 ========== */
#backToTop {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

#backToTop.show {
    opacity: 1;
    transform: translateY(0);
}

/* ========== 微信浏览器特殊处理 ========== */
/* 禁用微信浏览器字体缩放 */
body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* 禁用微信内置播放器控制条样式覆盖 */
video::-webkit-media-controls {
    overflow: visible !important;
}

/* ========== 安全区域适配（iPhone X及以上） ========== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
}

/* ========== 暗黑模式适配（可选） ========== */
@media (prefers-color-scheme: dark) {
    /* 暂不实现，阶段三可扩展 */
}

/* ========== 响应式断点 ========== */
/* 小屏手机（320px-375px） */
@media (max-width: 375px) {
    body {
        font-size: 13px;
    }
}

/* 大屏手机/平板（768px+） */
@media (min-width: 768px) {
    body {
        font-size: 15px;
    }

    .max-w-screen-xl {
        max-width: 768px;
    }
}

/* ========== 工具类 ========== */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ========== 内容卡片悬停效果 ========== */
.content-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.content-card:active {
    transform: scale(0.98);
}

/* ========== 分享按钮（阶段三） ========== */
.share-button {
    position: fixed;
    right: 16px;
    bottom: 80px;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 40;
}

/* ========== 性能优化 ========== */
/* GPU加速 */
.gpu-accelerated {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* ========== 打印样式 ========== */
@media print {
    header, footer, .no-print {
        display: none !important;
    }
}
