/**
 * 移动端优化样式
 * 提升小屏幕设备的用户体验
 */

/* ==================== 基础响应式优化 ==================== */

/* 移动端基础调整 */
@media (max-width: 768px) {
    /* 全局字体和间距 */
    body {
        font-size: 14px;
        line-height: 1.6;
    }
    
    h1 {
        font-size: 24px;
        margin-bottom: 15px;
    }
    
    h2 {
        font-size: 20px;
        margin-bottom: 12px;
    }
    
    h3 {
        font-size: 18px;
        margin-bottom: 10px;
    }
    
    h4 {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    p {
        font-size: 14px;
        margin-bottom: 12px;
    }
    
    /* 容器优化 */
    .container {
        padding: 15px;
        max-width: 100%;
    }
    
    /* 卡片样式优化 */
    .card {
        padding: 15px;
        margin-bottom: 15px;
        border-radius: 8px;
    }
    
    /* 按钮优化 - 增大触摸区域 */
    button, .btn {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
        border-radius: 8px;
        touch-action: manipulation;
    }
    
    /* 输入框优化 */
    input, textarea, select {
        min-height: 44px;
        padding: 10px 15px;
        font-size: 16px; /* 防止iOS自动缩放 */
        border-radius: 8px;
    }
    
    textarea {
        min-height: 100px;
    }
}

/* ==================== 塔罗牌显示优化 ==================== */

@media (max-width: 768px) {
    /* 牌阵容器 */
    .spread-container {
        padding: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* 单张牌优化 */
    .tarot-card {
        width: 80px !important;
        height: 140px !important;
        margin: 5px;
        font-size: 10px;
    }
    
    .tarot-card img {
        max-width: 100%;
        height: auto;
    }
    
    /* 牌名显示 */
    .card-name {
        font-size: 12px;
        padding: 5px;
        word-break: break-word;
    }
    
    /* 牌阵布局 - 三张牌 */
    .three-card-spread {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    /* 牌阵布局 - 凯尔特十字 */
    .celtic-cross-spread {
        transform: scale(0.7);
        transform-origin: top center;
    }
}

/* ==================== 解读结果优化 ==================== */

@media (max-width: 768px) {
    /* 解读区域 */
    .interpretation-section {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    /* 单张牌解读 */
    .card-interpretation {
        padding: 12px;
        margin-bottom: 12px;
        border-left: 3px solid #667eea;
    }
    
    .card-interpretation h4 {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .card-interpretation p {
        font-size: 14px;
        line-height: 1.6;
    }
    
    /* 关键词标签 */
    .keywords {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin: 10px 0;
    }
    
    .keyword-tag {
        padding: 4px 10px;
        font-size: 12px;
        border-radius: 12px;
        background: #f0f0f0;
        color: #667eea;
    }
    
    /* 总结区域 */
    .summary-section {
        padding: 15px;
        background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
        border-radius: 10px;
        margin: 15px 0;
    }
    
    .summary-section h3 {
        font-size: 18px;
        margin-bottom: 12px;
        color: #667eea;
    }
    
    /* 建议列表 */
    .advice-list {
        list-style: none;
        padding: 0;
    }
    
    .advice-list li {
        padding: 10px 0 10px 25px;
        position: relative;
        font-size: 14px;
        line-height: 1.6;
    }
    
    .advice-list li:before {
        content: "✨";
        position: absolute;
        left: 0;
    }
}

/* ==================== 导航和控制优化 ==================== */

@media (max-width: 768px) {
    /* 顶部导航 */
    .navbar {
        padding: 10px 15px;
        flex-wrap: wrap;
    }
    
    .navbar-brand {
        font-size: 18px;
    }
    
    .navbar-menu {
        width: 100%;
        margin-top: 10px;
    }
    
    .navbar-item {
        padding: 10px 0;
        border-bottom: 1px solid #eee;
    }
    
    /* 控制按钮组 */
    .control-buttons {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }
    
    .control-buttons button {
        width: 100%;
    }
    
    /* 牌阵选择器 */
    .spread-selector {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .spread-option {
        padding: 15px;
        text-align: center;
        border: 2px solid #e0e0e0;
        border-radius: 10px;
        cursor: pointer;
        transition: all 0.3s ease;
    }
    
    .spread-option:active {
        transform: scale(0.98);
    }
}

/* ==================== 模态框和弹窗优化 ==================== */

@media (max-width: 768px) {
    /* 模态框 */
    .modal {
        padding: 10px;
    }
    
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 20px auto;
        padding: 20px;
        border-radius: 10px;
    }
    
    .modal-header {
        padding: 15px;
        margin: -20px -20px 15px -20px;
    }
    
    .modal-body {
        padding: 15px 0;
        max-height: 60vh;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 15px;
        margin: 15px -20px -20px -20px;
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-footer button {
        width: 100%;
    }
}

/* ==================== 表格优化 ==================== */

@media (max-width: 768px) {
    /* 响应式表格 */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        font-size: 12px;
    }
    
    th, td {
        padding: 8px;
        white-space: nowrap;
    }
    
    /* 卡片式表格（更适合移动端） */
    .table-card-view {
        display: block;
    }
    
    .table-card-view thead {
        display: none;
    }
    
    .table-card-view tbody {
        display: block;
    }
    
    .table-card-view tr {
        display: block;
        margin-bottom: 15px;
        padding: 15px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        background: white;
    }
    
    .table-card-view td {
        display: block;
        text-align: left;
        padding: 8px 0;
        border: none;
    }
    
    .table-card-view td:before {
        content: attr(data-label);
        font-weight: bold;
        display: inline-block;
        width: 100px;
        color: #667eea;
    }
}

/* ==================== 图片和媒体优化 ==================== */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    .image-gallery {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }
    
    video {
        max-width: 100%;
        height: auto;
    }
}

/* ==================== 加载和动画优化 ==================== */

@media (max-width: 768px) {
    /* 减少动画以提升性能 */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
    
    /* 骨架屏 */
    .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; }
    }
}

/* ==================== 横屏优化 ==================== */

@media (max-width: 768px) and (orientation: landscape) {
    /* 横屏时减少垂直间距 */
    .container {
        padding: 10px 15px;
    }
    
    h1 {
        font-size: 20px;
        margin-bottom: 10px;
    }
    
    h2 {
        font-size: 18px;
        margin-bottom: 8px;
    }
    
    .card {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    /* 横屏时使用两列布局 */
    .two-column-landscape {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }
}

/* ==================== 深色模式支持 ==================== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .card {
        background: #2a2a2a;
        border-color: #3a3a3a;
    }
    
    input, textarea, select {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #3a3a3a;
    }
    
    .modal-content {
        background: #2a2a2a;
        color: #e0e0e0;
    }
    
    .keyword-tag {
        background: #3a3a3a;
        color: #8b9cff;
    }
    
    .summary-section {
        background: linear-gradient(135deg, #667eea25 0%, #764ba225 100%);
    }
}

/* ==================== 辅助功能优化 ==================== */

@media (max-width: 768px) {
    /* 增强焦点可见性 */
    *:focus {
        outline: 2px solid #667eea;
        outline-offset: 2px;
    }
    
    /* 跳过导航链接 */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: #667eea;
        color: white;
        padding: 8px;
        text-decoration: none;
        z-index: 100;
    }
    
    .skip-to-content:focus {
        top: 0;
    }
    
    /* 屏幕阅读器专用文本 */
    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border-width: 0;
    }
}

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

@media (max-width: 768px) {
    /* 使用GPU加速 */
    .accelerated {
        transform: translateZ(0);
        will-change: transform;
    }
    
    /* 优化滚动性能 */
    .smooth-scroll {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* 延迟加载图片 */
    img[loading="lazy"] {
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    img[loading="lazy"].loaded {
        opacity: 1;
    }
}

/* ==================== 小屏幕特殊优化 ==================== */

@media (max-width: 480px) {
    /* 超小屏幕进一步优化 */
    body {
        font-size: 13px;
    }
    
    h1 {
        font-size: 20px;
    }
    
    h2 {
        font-size: 18px;
    }
    
    .container {
        padding: 10px;
    }
    
    .card {
        padding: 12px;
    }
    
    button, .btn {
        padding: 10px 15px;
        font-size: 14px;
    }
    
    /* 塔罗牌进一步缩小 */
    .tarot-card {
        width: 60px !important;
        height: 105px !important;
        margin: 3px;
        font-size: 9px;
    }
}

/* ==================== 打印优化 ==================== */

@media print {
    /* 隐藏不必要的元素 */
    .navbar,
    .control-buttons,
    button,
    .modal,
    .error-toast {
        display: none !important;
    }
    
    /* 优化打印布局 */
    body {
        font-size: 12pt;
        color: black;
        background: white;
    }
    
    .card {
        page-break-inside: avoid;
        border: 1px solid #000;
    }
    
    h1, h2, h3 {
        page-break-after: avoid;
    }
}
