/* ============================================
   心镜免费自测小站 - 兼容性优化样式
   支持：Chrome, Firefox, Safari, Edge, UC浏览器, 微信浏览器, 各种移动设备
   ============================================ */

/* CSS 变量（兼容性处理） */
:root {
    --bg: #ffffff;
    --card: #ffffff;
    --text: #333333;
    --muted: #666666;
    --border: #e0e0e0;
    --brand: #6a3de8;
    --primary: #6a3de8;
    --secondary: #9c7af2;
    --light-purple: #f5f0ff;
    --brand-2: #5932c4;
    --ok: #34a853;
    --warn: #fbbc05;
    --error: #ea4335;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --gradient-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

/* 基础重置 */
*, *::before, *::after {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* HTML 和 Body */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    /* 防止 iOS Safari 字体大小自动调整 */
    text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
    line-height: 1.5;
    color: #333333;
    background: linear-gradient(204deg, #28026f 0%, #011b5d 50%, #0f5b60 100%);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 萤火虫背景 Canvas */
#firefly-canvas {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    -webkit-pointer-events: none;
}

/* ============================================
   网站头部
   ============================================ */
.site-header {
    text-align: center;
    padding: 40px 16px 16px;
    background: transparent;
    position: relative;
    z-index: 1;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* 标题渐变效果（兼容性处理） */
.site-header h1 {
    font-size: 2.4em;
    margin: 0;
    letter-spacing: 2px;
    position: relative;
    /* 渐变文字 - 主流浏览器 */
    background: linear-gradient(90deg, #ffffff, #ffd700, #ffffff, #4ecdc4, #ffffff);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    /* 兼容旧浏览器：显示纯白色 */
    color: #ffffff;
    /* 动画 */
    -webkit-animation: gradientFlow 3s ease infinite, fadeInDown 0.6s ease;
    animation: gradientFlow 3s ease infinite, fadeInDown 0.6s ease;
    /* 文字阴影效果 */
    text-shadow: 0 0 30px rgba(255,215,0,0.5), 0 0 60px rgba(78,205,196,0.3);
    /* 强制 GPU 渲染 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: background-position;
}

/* 渐变动画 */
@-webkit-keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 入场动画 */
@-webkit-keyframes fadeInDown {
    from { opacity: 0; -webkit-transform: translateY(-20px); transform: translateY(-20px); }
    to { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); }
}
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@-webkit-keyframes fadeInUp {
    from { opacity: 0; -webkit-transform: translateY(20px); transform: translateY(20px); }
    to { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 副标题 */
.site-header .subtitle {
    color: rgb(255 255 255 / 55%);
    font-size: 0.95em;
    margin: 8px 0 0;
    -webkit-animation: fadeInUp 0.6s ease 0.2s both;
    animation: fadeInUp 0.6s ease 0.2s both;
    text-shadow: 0 0 20px rgba(255,255,255,0.3);
}

/* ============================================
   分类容器
   ============================================ */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
}

.categories-container {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    max-width: 900px;
    margin: 0 auto;
    z-index: 1;
    position: relative;
}

/* 修复 gap 属性在旧浏览器不支持 */
@supports (gap: 16px) {
    .categories-container {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 20px;
    }
}

/* ============================================
   分类卡片
   ============================================ */
.category-card {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 16px;
    background: rgba(255,255,255,0.95);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 16px;
    cursor: pointer;
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
    -webkit-box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    -webkit-animation: cardPop 0.5s ease both;
    animation: cardPop 0.5s ease both;
    position: relative;
    overflow: hidden;
    width: calc(50% - 12px);
    min-width: 280px;
    max-width: 420px;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* 触摸设备优化 */
    -webkit-tap-highlight-color: transparent;
    tap-highlight-color: transparent;
}

/* 修复 gap */
.category-card > * {
    margin-right: 16px;
}
.category-card > *:last-child {
    margin-right: 0;
}

/* 卡片动画延迟 */
.category-card:nth-child(1) { -webkit-animation-delay: 0.1s; animation-delay: 0.1s; }
.category-card:nth-child(2) { -webkit-animation-delay: 0.15s; animation-delay: 0.15s; }
.category-card:nth-child(3) { -webkit-animation-delay: 0.2s; animation-delay: 0.2s; }
.category-card:nth-child(4) { -webkit-animation-delay: 0.25s; animation-delay: 0.25s; }
.category-card:nth-child(5) { -webkit-animation-delay: 0.3s; animation-delay: 0.3s; }
.category-card:nth-child(6) { -webkit-animation-delay: 0.35s; animation-delay: 0.35s; }

@-webkit-keyframes cardPop {
    from { opacity: 0; -webkit-transform: scale(0.95) translateY(20px); transform: scale(0.95) translateY(20px); }
    to { opacity: 1; -webkit-transform: scale(1) translateY(0); transform: scale(1) translateY(0); }
}
@keyframes cardPop {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* 卡片悬停/触摸效果 */
.category-card:hover,
.category-card:active {
    -webkit-transform: translateY(-4px);
    transform: translateY(-4px);
    -webkit-box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

/* 卡片顶部渐变条 */
.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0px;
    background: -webkit-linear-gradient(left, #667eea, #764ba2);
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 16px 16px 0 0;
}

/* 分类图标 - 左侧固定宽度 */
.category-icon {
    width: 60px;
    height: 60px;
    min-width: 60px;
    font-size: 2.2em;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    background: -webkit-linear-gradient(135deg, #f5f0ff 0%, #ebe5ff 100%);
    background: linear-gradient(135deg, #f5f0ff 0%, #ebe5ff 100%);
    border-radius: 12px;
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
    -webkit-animation: bounce 2s ease infinite;
    animation: bounce 2s ease infinite;
    -webkit-user-select: none;
    user-select: none;
}

@-webkit-keyframes bounce {
    0%, 100% { -webkit-transform: translateY(0); transform: translateY(0); }
    50% { -webkit-transform: translateY(-5px); transform: translateY(-5px); }
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* 分类内容 - 右侧自适应 */
.category-content {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    min-width: 0;
    text-align: left;
}

.category-content h3 {
    font-size: 1em;
    color: #333333;
    margin: 0 0 4px 0;
    font-weight: 600;
    word-break: break-word;
    white-space: nowrap;
    overflow: hidden;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
}

.category-desc {
    color: #666666;
    font-size: 0.8em;
    margin: 0 0 4px 0;
    line-height: 1.3;
    word-break: break-word;
    white-space: nowrap;
    overflow: hidden;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
}

.category-count {
    color: #999999;
    font-size: 0.75em;
    margin: 0;
}

/* ============================================
   测试列表部分
   ============================================ */
#tests-section {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
    z-index: 1;
    position: relative;
}

.hidden {
    display: none !important;
}

/* 分类头部 */
.category-header {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    margin-top: 8px;
}

/* 修复 gap */
.category-header > * {
    margin-right: 12px;
}
.category-header > *:last-child {
    margin-right: 0;
}

/* 返回按钮 */
.back-button {
    background: rgba(255,255,255,0.1);
    border: none;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    color: #ffffff;
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.back-button:hover,
.back-button:active {
    background: rgba(255,255,255,0.2);
    -webkit-transform: scale(1.05);
    transform: scale(1.05);
}

/* 当前分类标题 */
#current-category {
    color: #ffffff;
    font-size: 1.3em;
    margin: 0;
    line-height: 1.4;
    text-shadow: 0 2px 8px rgba(0,0,0,0.2);
    word-break: break-word;
}

/* 测试列表 */
.test-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    gap: 10px;
}

/* 修复 gap */
.test-list > li {
    margin-bottom: 10px;
}

@supports (gap: 10px) {
    .test-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 10px;
    }
    .test-list > li {
        margin-bottom: 0;
    }
}

/* 测试项目 */
.test-item {
    background: rgba(255,255,255,0.95);
    border-radius: 12px;
    overflow: hidden;
    -webkit-transition: all 0.25s ease;
    transition: all 0.25s ease;
    -webkit-animation: fadeIn 0.3s ease both;
    animation: fadeIn 0.3s ease both;
    -webkit-box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    min-width: 200px;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.test-item:nth-child(1) { -webkit-animation-delay: 0.03s; animation-delay: 0.03s; }
.test-item:nth-child(2) { -webkit-animation-delay: 0.06s; animation-delay: 0.06s; }
.test-item:nth-child(3) { -webkit-animation-delay: 0.09s; animation-delay: 0.09s; }
.test-item:nth-child(4) { -webkit-animation-delay: 0.12s; animation-delay: 0.12s; }
.test-item:nth-child(5) { -webkit-animation-delay: 0.15s; animation-delay: 0.15s; }

@-webkit-keyframes fadeIn {
    from { opacity: 0; -webkit-transform: translateY(8px); transform: translateY(8px); }
    to { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.test-item:hover,
.test-item:active {
    -webkit-transform: translateY(-3px);
    transform: translateY(-3px);
    -webkit-box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

/* 测试链接 */
.test-link {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    padding: 10px 12px;
    text-decoration: none;
    gap: 10px;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

/* 修复 gap */
.test-link > * {
    margin-right: 10px;
}
.test-link > *:last-child {
    margin-right: 0;
}

/* 测试封面图 */
.test-cover {
    width: 48px;
    height: 48px;
    -webkit-object-fit: cover;
    object-fit: cover;
    border-radius: 8px;
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
    display: block;
}

/* 测试 Emoji */
.test-emoji {
    width: 48px;
    height: 48px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    font-size: 1.6em;
    background: -webkit-linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border-radius: 8px;
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}

/* 测试信息容器 */
.test-info-box {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    min-width: 0;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
}

.test-title {
    display: block;
    font-size: 0.9em;
    color: #333333;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
    word-break: break-word;
}

.test-info {
    display: block;
    color: #888888;
    font-size: 0.8em;
}

/* ============================================
   页脚
   ============================================ */
.site-footer {
    text-align: center;
    padding: 24px 16px;
    color: rgba(255,255,255,0.7);
    font-size: 0.85em;
    z-index: 1;
    position: relative;
    line-height: 1.6;
}

.site-footer p {
    margin: 4px 0;
}

.site-footer a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
}

/* ============================================
   响应式设计 - 移动端优化
   ============================================ */

/* 大屏手机和小平板 (480px - 768px) */
@media screen and (max-width: 768px) {
    html {
        font-size: 15px;
    }

    .site-header {
        padding: 30px 12px 12px;
    }

    .site-header h1 {
        font-size: 1.8em;
        letter-spacing: 1px;
    }

    .site-header .subtitle {
        font-size: 0.85em;
    }

    .categories-container {
        padding: 12px;
        gap: 12px;
    }

    .category-card {
        padding: 14px;
        width: calc(100% - 24px);
        min-width: 240px;
        gap: 12px;
    }

    .category-icon {
        width: 50px;
        height: 50px;
        min-width: 50px;
        font-size: 1.8em;
    }

    .category-content h3 {
        font-size: 1em;
    }

    .category-desc {
        font-size: 0.8em;
    }

    .test-list {
        gap: 8px;
    }

    .test-link {
        padding: 8px 10px;
    }

    #current-category {
        font-size: 1.1em;
    }
}

/* 小屏手机 (< 480px) */
@media screen and (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .site-header {
        padding: 36px 8px 8px;
    }

    .site-header h1 {
        font-size: 1.5em;
        letter-spacing: 0;
    }

    .site-header .subtitle {
        font-size: 0.8em;
    }

    .categories-container {
        padding: 8px;
        gap: 10px;
    }

    .category-card {
        padding: 12px;
        width: 100%;
        min-width: auto;
        border-radius: 12px;
        gap: 10px;
    }

    .category-icon {
        width: 44px;
        height: 44px;
        min-width: 44px;
        font-size: 1.6em;
        border-radius: 10px;
    }

    .category-content h3 {
        font-size: 0.9em;
        margin-bottom: 3px;
    }

    .category-desc {
        font-size: 0.7em;
        margin-bottom: 3px;
    }

    .category-count {
        font-size: 0.7em;
    }

    #tests-section {
        padding: 8px;
    }

    .category-header {
        gap: 8px;
        margin-bottom: 12px;
    }

    .back-button {
        padding: 6px 10px;
        font-size: 0.85em;
    }

    #current-category {
        font-size: 1em;
    }

    .test-list {
        gap: 6px;
    }

    .test-item {
        min-width: 160px;
        border-radius: 10px;
    }

    .test-link {
        padding: 8px;
        gap: 8px;
    }

    .test-cover,
    .test-emoji {
        width: 40px;
        height: 40px;
        font-size: 1.4em;
    }

    .test-title {
        font-size: 0.85em;
    }

    .test-info {
        font-size: 0.7em;
    }

    .site-footer {
        padding: 16px 8px;
        font-size: 0.75em;
    }
}

/* 超小屏 (< 360px) - 如旧款安卓手机 */
@media screen and (max-width: 360px) {
    html {
        font-size: 13px;
    }

    .site-header h1 {
        font-size: 1.3em;
    }

    .category-card {
        padding: 10px;
        gap: 8px;
    }

    .category-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 1.4em;
        border-radius: 8px;
    }

    .test-item {
        min-width: 140px;
    }

    .test-cover,
    .test-emoji {
        width: 36px;
        height: 36px;
        font-size: 1.2em;
    }
}

/* ============================================
   特殊浏览器兼容
   ============================================ */

/* UC浏览器、QQ浏览器等国产浏览器 */
@media screen and (max-width: 480px) and (-webkit-max-device-pixel-ratio: 3) {
    .category-card {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        background: #ffffff;
    }

    .test-item {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        background: #ffffff;
    }
}

/* 微信内置浏览器 */
@media screen and (max-width: 480px) {
    /* 微信浏览器不支持某些CSS特性，提供降级方案 */
    .site-header h1 {
        /* 如果渐变文字不支持，显示纯色 */
        color: #ffffff;
    }

    .category-card::before {
        /* 简化渐变条 */
        background: #667eea;
    }
}

/* iOS Safari 特殊处理 */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari 100vh 问题修复 */
    .site-header,
    .categories-container,
    #tests-section,
    .site-footer {
        min-height: auto;
    }

    /* 防止 iOS Safari 卡片点击闪烁 */
    .category-card,
    .test-item {
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
}

/* ============================================
   打印样式
   ============================================ */
@media print {
    #firefly-canvas {
        display: none;
    }

    body {
        background: #ffffff;
    }

    .site-header h1 {
        color: #333333;
        background: none;
        -webkit-text-fill-color: #333333;
    }

    .category-card,
    .test-item {
        background: #ffffff;
        -webkit-box-shadow: none;
        box-shadow: none;
    }
}

/* ============================================
   无障碍支持
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-animation-iteration-count: 1 !important;
        animation-iteration-count: 1 !important;
        -webkit-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .category-card,
    .test-item {
        border: 2px solid #333333;
    }

    .site-header h1 {
        color: #ffffff;
        text-shadow: none;
    }
}