/**
 * 移动端性能优化CSS - 声音疗愈应用
 * 专注于触摸体验、电池续航和网络适配
 */

/* =============================================
   移动端基础优化
   ============================================= */

/* 移动设备特定viewport设置 */
@viewport {
    width: device-width;
    initial-scale: 1;
    maximum-scale: 5;
    user-scalable: yes;
}

/* 触摸优化 */
* {
    -webkit-tap-highlight-color: rgba(127, 176, 105, 0.3);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* 可选择文本的元素 */
.nature-title,
.path-title,
.track-title,
.current-track-name {
    -webkit-user-select: text;
    user-select: text;
}

/* =============================================
   响应式网格布局
   ============================================= */

.ecosystem-grid {
    display: grid;
    gap: 1rem;
    padding: 0 1rem;
    /* 移动端适配网格 */
    grid-template-columns: 1fr;
    contain: layout style;
}

@media (min-width: 480px) {
    .ecosystem-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 1.5rem;
    }
}

@media (min-width: 768px) {
    .ecosystem-grid {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 2rem;
        padding: 0 2rem;
    }
}

@media (min-width: 1024px) {
    .ecosystem-grid {
        grid-template-columns: repeat(3, 1fr);
        max-width: 1200px;
        margin: 0 auto;
    }
}

/* =============================================
   触摸友好的交互元素
   ============================================= */

/* 最小触摸目标尺寸 44px */
.ecosystem-card,
.lotus-player,
.nature-control-btn,
.nature-button,
.track-item {
    min-height: 44px;
    min-width: 44px;
    position: relative;
    cursor: pointer;
}

/* 扩大触摸区域 */
.nature-control-btn::before,
.lotus-player::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    z-index: -1;
}

/* 移动端按钮样式优化 */
@media (max-width: 768px) {
    .nature-control-btn {
        padding: 12px;
        font-size: 18px;
        border-radius: 12px;
    }
    
    .ecosystem-card {
        padding: 1.5rem;
        font-size: 16px;
        line-height: 1.5;
    }
    
    .lotus-player {
        width: 80px;
        height: 80px;
        font-size: 28px;
    }
}

/* =============================================
   滑块和进度条优化
   ============================================= */

.nature-progress-slider,
.nature-slider {
    height: 8px;
    border-radius: 4px;
    /* 移动端更大的滑块手柄 */
}

.nature-progress-slider::-webkit-slider-thumb,
.nature-slider::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--nature-sage);
    border: 3px solid var(--nature-cream);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    /* 触摸反馈 */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.nature-progress-slider::-webkit-slider-thumb:active,
.nature-slider::-webkit-slider-thumb:active {
    transform: scale(1.3);
    box-shadow: 0 4px 12px rgba(127, 176, 105, 0.4);
}

/* Firefox滑块优化 */
.nature-progress-slider::-moz-range-thumb,
.nature-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--nature-sage);
    border: 3px solid var(--nature-cream);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* =============================================
   移动端布局适配
   ============================================= */

/* 小屏幕优化 */
@media (max-width: 480px) {
    body {
        font-size: 14px;
        line-height: 1.6;
    }
    
    .nature-header {
        padding: 1rem;
        text-align: center;
    }
    
    .nature-title {
        font-size: 2rem;
        margin-bottom: 0.5rem;
    }
    
    .nature-subtitle {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    /* 简化季节指示器 */
    .season-indicator {
        display: flex;
        justify-content: center;
        gap: 0.5rem;
    }
    
    .season {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    
    /* 播放器区域优化 */
    .pond-player {
        margin: 2rem auto;
        padding: 1rem;
    }
    
    /* 控制台移动到底部 */
    .nature-console {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(26, 46, 26, 0.95);
        backdrop-filter: blur(20px);
        padding: 1rem;
        border-top: 1px solid rgba(127, 176, 105, 0.3);
        z-index: 1000;
    }
    
    /* 为底部控制台留出空间 */
    body {
        padding-bottom: 100px;
    }
}

/* =============================================
   性能优化类
   ============================================= */

/* 低功耗模式 */
@media (prefers-reduced-motion: reduce) {
    .cloud,
    .ripple,
    .background-scene {
        animation: none !important;
        display: none !important;
    }
    
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* 低电量模式检测 */
.low-battery {
    /* 禁用所有动画和效果 */
}

.low-battery .cloud,
.low-battery .ripple,
.low-battery .background-scene {
    display: none !important;
}

.low-battery .ecosystem-card:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* 慢速网络适配 */
@media (max-width: 768px) and (prefers-reduced-data: reduce) {
    .background-scene,
    .clouds {
        display: none !important;
    }
    
    /* 简化视觉效果 */
    .ecosystem-card {
        background: rgba(45, 74, 45, 0.6);
        backdrop-filter: none;
    }
    
    /* 减少阴影效果 */
    * {
        box-shadow: none !important;
    }
}

/* =============================================
   横屏适配
   ============================================= */

@media (orientation: landscape) and (max-height: 600px) {
    .nature-header {
        padding: 0.5rem 1rem;
    }
    
    .nature-title {
        font-size: 1.8rem;
    }
    
    .pond-player {
        margin: 1rem auto;
    }
    
    .lotus-player {
        width: 60px;
        height: 60px;
        font-size: 20px;
    }
    
    /* 横屏时隐藏装饰元素 */
    .clouds,
    .background-scene {
        display: none;
    }
}

/* =============================================
   Dark Mode支持
   ============================================= */

@media (prefers-color-scheme: dark) {
    :root {
        --nature-cream: #f7f4e9;
        --nature-dark: #1a2e1a;
    }
    
    /* 暗色模式下的对比度调整 */
    .ecosystem-card {
        background: rgba(20, 35, 20, 0.9);
        color: var(--nature-cream);
    }
    
    .nature-console {
        background: rgba(15, 25, 15, 0.95);
    }
}

/* =============================================
   播放列表移动端优化
   ============================================= */

@media (max-width: 768px) {
    .playlist-section {
        padding: 1rem !important;
    }
    
    .playlist-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .habitat-controls {
        display: flex;
        justify-content: center;
        gap: 1rem;
    }
    
    .track-item {
        padding: 1rem !important;
        margin: 0.5rem 0 !important;
        border-radius: 8px !important;
    }
    
    .track-header {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }
    
    .track-number {
        width: 32px !important;
        height: 32px !important;
        line-height: 32px !important;
        font-size: 14px;
        flex-shrink: 0;
    }
    
    .track-title {
        font-size: 14px !important;
        line-height: 1.4;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
    }
}

/* =============================================
   无障碍优化
   ============================================= */

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .ecosystem-card {
        border: 2px solid var(--nature-sage);
        background: var(--nature-dark);
    }
    
    .nature-control-btn {
        border: 1px solid var(--nature-cream);
    }
    
    .lotus-player {
        border: 3px solid var(--nature-sage);
        background: var(--nature-dark);
    }
}

/* 焦点指示器 */
.ecosystem-card:focus,
.nature-control-btn:focus,
.lotus-player:focus {
    outline: 3px solid var(--nature-sage);
    outline-offset: 2px;
}

/* =============================================
   设备特定优化
   ============================================= */

/* iPhone SE等小屏设备 */
@media (max-width: 375px) {
    .ecosystem-grid {
        padding: 0 0.5rem;
        gap: 0.75rem;
    }
    
    .ecosystem-card {
        padding: 1rem;
        font-size: 14px;
    }
    
    .nature-console {
        padding: 0.75rem;
    }
    
    .nature-control-btn {
        padding: 8px;
        font-size: 16px;
    }
}

/* 大屏手机优化 */
@media (min-width: 414px) and (max-width: 768px) {
    .ecosystem-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }
    
    .lotus-player {
        width: 90px;
        height: 90px;
        font-size: 32px;
    }
}

/* =============================================
   性能监控辅助类
   ============================================= */

/* 开发模式：显示触摸区域 */
.debug-touch .ecosystem-card::before,
.debug-touch .nature-control-btn::before {
    border: 1px dashed rgba(255, 0, 0, 0.5);
}

/* 网络状态指示 */
.network-slow .ecosystem-card {
    opacity: 0.8;
}

.network-offline .ecosystem-card {
    opacity: 0.6;
    filter: grayscale(0.3);
}