/**
 * 触摸设备专用样式
 * 增强移动设备上的用户体验
 */

/* 通用触摸优化 */
@media (hover: none) {
    /* 防止iOS点击时的高亮效果 */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    /* 全局性能优化 */
    body {
        touch-action: pan-x pan-y;
        -webkit-text-size-adjust: 100%;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    /* 使用更强的GPU加速提高滚动流畅度 */
    .scrollable,
    .scrollable-x,
    .scrollable-y,
    [class*="scroll"],
    [style*="overflow"] {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        transform: translateZ(0) scale(1.0);
        will-change: scroll-position;
        backface-visibility: hidden;
        perspective: 1000px;
        scroll-behavior: smooth;
    }
    
    /* 增强按钮触摸体验 */
    button, 
    .btn,
    .menu-item,
    .prompt-btn,
    .size-option,
    .lang-dropdown button,
    .feature-tag {
        cursor: pointer;
        touch-action: manipulation;
        transition: transform 0.1s ease-out, opacity 0.1s ease-out, background-color 0.15s ease;
        user-select: none;
        -webkit-user-select: none;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    
    button:active, 
    .btn:active,
    .menu-item:active,
    .prompt-btn:active,
    .size-option:active,
    .lang-dropdown button:active,
    .feature-tag:active {
        opacity: 0.75;
        transform: scale(0.97);
        transition: transform 0.05s ease-out, opacity 0.05s ease-out;
    }
    
    /* 按钮触摸时的视觉反馈 */
    button::after,
    .btn::after,
    .menu-item::after,
    .prompt-btn::after,
    .size-option::after,
    .lang-dropdown button::after,
    .feature-tag::after {
        content: "";
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: radial-gradient(circle, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 70%);
        opacity: 0;
        transform: scale(2);
        pointer-events: none;
        transition: opacity 0.5s ease, transform 0.5s ease;
        border-radius: inherit;
    }
    
    button:active::after,
    .btn:active::after,
    .menu-item:active::after,
    .prompt-btn:active::after,
    .size-option:active::after,
    .lang-dropdown button:active::after,
    .feature-tag:active::after {
        opacity: 1;
        transform: scale(1);
        transition: opacity 0.1s ease, transform 0.1s ease;
    }
    
    /* 优化滚动容器 */
    .prompts-container,
    .testimonials-scroll,
    .horizontal-scroll,
    .image-gallery,
    .results-container,
    [class*="scroll-container"] {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none; /* Firefox */
        overscroll-behavior-x: contain;
        transform: translateZ(0);
        will-change: scroll-position;
        scroll-behavior: smooth;
        /* 增加惯性 */
        -ms-scroll-chaining: none;
        padding-bottom: 5px; /* 防止底部滚动条显示问题 */
        /* 优化触摸反馈 */
        cursor: grab;
        -webkit-tap-highlight-color: transparent;
        transition: transform 0.2s ease, background-color 0.2s ease;
    }
    
    /* 滚动容器触摸滚动状态样式 */
    .prompts-container.scrolling,
    .testimonials-scroll.scrolling,
    .horizontal-scroll.scrolling,
    .image-gallery.scrolling,
    .results-container.scrolling,
    [class*="scroll-container"].scrolling {
        cursor: grabbing;
        background-color: rgba(255, 255, 255, 0.03);
    }
    
    /* 应用于所有可滚动子元素 */
    .prompts-container > *,
    .testimonials-scroll > *,
    .horizontal-scroll > *,
    .image-gallery > *,
    .results-container > *,
    [class*="scroll-container"] > * {
        scroll-snap-align: center;
        transform: translateZ(0);
        will-change: transform;
        touch-action: pan-x pan-y;
        user-select: none;
        /* 提高边界清晰度 */
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    
    /* 为滚动容器内的子元素添加轻微的悬停状态 */
    .prompts-container > *:active,
    .testimonials-scroll > *:active,
    .horizontal-scroll > *:active,
    .image-gallery > *:active,
    .results-container > *:active,
    [class*="scroll-container"] > *:active {
        transform: translateZ(0) scale(0.98);
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    /* 增加触摸按下状态 */
    .prompts-container:active,
    .testimonials-scroll:active,
    .horizontal-scroll:active,
    .image-gallery:active,
    .results-container:active,
    [class*="scroll-container"]:active {
        cursor: grabbing;
    }
    
    .prompts-container::-webkit-scrollbar,
    .testimonials-scroll::-webkit-scrollbar,
    .horizontal-scroll::-webkit-scrollbar,
    .image-gallery::-webkit-scrollbar,
    .results-container::-webkit-scrollbar,
    [class*="scroll-container"]::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Edge */
    }
    
    /* 添加滑动指示器 */
    .scroll-indicator {
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 6px;
        z-index: 10;
    }
    
    .scroll-indicator-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background-color: rgba(255, 255, 255, 0.3);
        transition: background-color 0.3s ease, transform 0.15s ease;
        box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    }
    
    .scroll-indicator-dot.active {
        background-color: var(--primary-color);
        transform: scale(1.1);
    }
    
    /* 表单和输入优化 */
    input, 
    select, 
    textarea {
        font-size: 16px !important; /* 防止iOS上的自动缩放 */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 0;
        touch-action: manipulation;
        transition: border-color 0.15s ease, box-shadow 0.15s ease;
    }
    
    input:focus,
    select:focus,
    textarea:focus {
        outline: none;
        box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.4);
    }
    
    /* 确保可点击区域足够大 */
    .prompt-btn,
    .size-option,
    .menu-item,
    .lang-dropdown button {
        min-height: 48px; /* 增加高度，提高可点击性 */
        min-width: 48px;  /* 增加宽度，提高可点击性 */
        padding: 10px 16px;
        position: relative;
        overflow: hidden; /* 为触摸涟漪效果准备 */
    }
    
    /* 添加触摸涟漪效果 */
    .ripple {
        position: absolute;
        background: rgba(255, 255, 255, 0.35);
        border-radius: 50%;
        transform: scale(0);
        pointer-events: none;
        animation: ripple-effect 0.6s linear;
    }
    
    .ripple.active {
        animation: ripple-effect 0.6s linear;
    }
    
    @keyframes ripple-effect {
        to {
            transform: scale(2.5);
            opacity: 0;
        }
    }
    
    /* 优化页脚布局，减小行间距使显示更紧凑 */
    footer {
        padding-top: 20px;
        padding-bottom: 10px;
        transform: translateZ(0);
        will-change: transform;
    }
    
    .footer-content {
        padding: 10px;
    }
    
    .footer-logo {
        margin-bottom: 8px;
    }
    
    .footer-logo img {
        height: 35px;
        margin-bottom: 4px;
    }
    
    .footer-logo span {
        font-size: 1rem;
    }
    
    .footer-description p {
        font-size: 0.8rem;
        line-height: 1.3;
        margin-bottom: 8px;
    }
    
    .footer-links {
        gap: 8px;
        margin-bottom: 8px;
    }
    
    .footer-link {
        padding: 6px 8px;
        font-size: 0.85rem;
        position: relative;
        overflow: hidden;
    }
    
    .footer-copyright {
        margin-top: 8px;
        font-size: 0.7rem;
        line-height: 1.2;
    }
    
    /* 更小屏幕进一步优化 */
    @media (max-width: 480px) {
        .footer-content {
            padding: 8px 5px;
        }
        
        .footer-logo {
            margin-bottom: 6px;
        }
        
        .footer-logo img {
            height: 30px;
            margin-bottom: 3px;
        }
        
        .footer-description p {
            font-size: 0.75rem;
            line-height: 1.2;
            margin-bottom: 6px;
        }
        
        .footer-links {
            gap: 6px;
            margin-bottom: 6px;
        }
        
        .footer-link {
            padding: 5px 6px;
            font-size: 0.8rem;
        }
        
        .footer-copyright {
            margin-top: 6px;
            font-size: 0.65rem;
            line-height: 1.1;
        }
    }
    
    /* 超小屏幕最大程度优化 */
    @media (max-width: 375px) {
        .footer-content {
            padding: 6px 4px;
        }
        
        .footer-logo img {
            height: 28px;
            margin-bottom: 2px;
        }
        
        .footer-description p {
            font-size: 0.7rem;
            line-height: 1.1;
            margin-bottom: 5px;
        }
        
        .footer-links {
            gap: 4px;
            margin-bottom: 5px;
        }
        
        .footer-link {
            padding: 4px 5px;
            font-size: 0.75rem;
            border-radius: 6px;
        }
        
        .footer-copyright {
            margin-top: 5px;
            font-size: 0.6rem;
            line-height: 1;
        }
    }
    
    /* 增强触摸滑动动画效果 */
    @keyframes touchPulse {
        0% { transform: scale(1); }
        50% { transform: scale(0.98); }
        100% { transform: scale(1); }
    }
    
    /* 添加触摸拖动指引 */
    .drag-hint {
        position: absolute;
        top: 50%;
        right: 15px;
        width: 40px;
        height: 40px;
        transform: translateY(-50%);
        background: rgba(79, 172, 254, 0.2);
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        animation: swipeHint 1.5s infinite;
        pointer-events: none;
        z-index: 5;
        box-shadow: 0 0 15px rgba(79, 172, 254, 0.4);
    }
    
    @keyframes swipeHint {
        0%, 100% { opacity: 0; transform: translateY(-50%) translateX(0); }
        50% { opacity: 1; transform: translateY(-50%) translateX(-10px); }
    }
    
    /* 消除Safari橡皮筋效果 */
    html {
        overflow: hidden;
        height: 100%;
    }
    
    body {
        overflow: auto;
        height: 100%;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: none;
    }
    
    /* 添加交互动态效果支持 */
    .touch-anim {
        transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.15s ease;
    }
    
    .touch-anim:active {
        transform: scale(0.97);
        opacity: 0.85;
    }
    
    /* 优化可点击图像 */
    img[onclick], 
    img[role="button"],
    .clickable-img {
        touch-action: manipulation;
        transform: translateZ(0);
        will-change: transform;
        transition: transform 0.15s ease-out, filter 0.15s ease-out;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        -webkit-user-select: none;
    }
    
    img[onclick]:active, 
    img[role="button"]:active,
    .clickable-img:active {
        transform: scale(0.98);
        filter: brightness(0.95);
    }
    
    /* 增强滚动容器的触摸体验 */
    .touch-scroll-x {
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding-bottom: 5px;
        transform: translateZ(0);
        will-change: scroll-position;
        scroll-behavior: smooth;
        touch-action: pan-x;
    }
    
    .touch-scroll-y {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: y mandatory;
        padding-right: 5px;
        transform: translateZ(0);
        will-change: scroll-position;
        scroll-behavior: smooth;
        touch-action: pan-y;
    }
    
    /* 加载状态优化 */
    .loading-indicator {
        transition: opacity 0.2s ease-out;
        animation: pulse 1.5s infinite ease-in-out;
    }
    
    @keyframes pulse {
        0%, 100% { opacity: 0.6; }
        50% { opacity: 1; }
    }
}

/* iPad特定优化 */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
    /* 优化iPad上的表单元素 */
    button, input[type="button"], input[type="submit"] {
        padding: 12px 20px;
    }
    
    /* 提升对比度和清晰度 */
    .description h1 {
        text-shadow: 0 0 15px rgba(79, 172, 254, 0.4);
    }
}

/* 移动设备方向变化优化 */
@media screen and (orientation: portrait) {
    /* 竖屏特定样式 */
    .testimonial {
        width: 90%;
    }
}

@media screen and (orientation: landscape) and (max-height: 500px) {
    /* 横屏特定样式，尤其是键盘打开时 */
    header {
        position: absolute;
    }
    
    main {
        padding-top: 70px;
    }
    
    .prompt-input textarea {
        max-height: 60px;
    }
}

/* 兼容浏览器工具栏的高度变化 */
@supports (-webkit-touch-callout: none) {
    /* iOS特定修复 */
    .main {
        min-height: -webkit-fill-available;
    }
    
    body {
        height: 100vh;
        height: -webkit-fill-available;
    }
}

/* 键盘打开时的样式调整 */
body.keyboard-open {
    /* 防止iOS键盘打开时的内容位移问题 */
    height: auto !important;
}

body.keyboard-open .prompt-input textarea {
    /* 确保文本区域在键盘打开时可见 */
    position: relative;
    z-index: 2;
}

body.keyboard-open section:not(.prompt-section) {
    /* 减少其他区域占用的空间 */
    display: none;
}

body.keyboard-open header {
    /* 简化头部 */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

body.keyboard-open .prompt-section {
    /* 确保提示区域可见 */
    margin-top: 60px;
    height: calc(100vh - 60px);
} 