/**
 * 千智风声 - 移动端响应式样式
 * 适配手机屏幕，优化触摸体验
 */

/* ==================== 基础移动端适配 ==================== */

/* 防止文本缩放 */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* 禁用双击缩放 */
* {
    touch-action: manipulation;
}

/* ==================== 手机竖屏 (小于768px) ==================== */
@media (max-width: 768px) {
    
    /* ===== 大厅页面适配 ===== */
    .main-container {
        padding: 0.5rem;
    }
    
    .game-header {
        padding: 1rem 0.5rem;
    }
    
    .game-title {
        font-size: 2rem;
    }
    
    .game-subtitle {
        font-size: 0.875rem;
    }
    
    /* 登录区域 */
    .login-section {
        padding: 1.5rem 1rem;
        margin: 0 0.5rem;
    }
    
    .nickname-input {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 0.875rem;
    }
    
    /* 头像选择 - 改为4列 */
    .avatar-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
    }
    
    .avatar-item {
        width: 60px;
        height: 60px;
    }
    
    /* 按钮 */
    .action-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        min-height: 48px; /* 触摸友好 */
    }
    
    /* 房间列表 */
    .room-list {
        padding: 0.5rem;
    }
    
    .room-item {
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem;
    }
    
    .room-info {
        width: 100%;
    }
    
    .room-actions {
        width: 100%;
        justify-content: stretch;
    }
    
    .room-actions .btn {
        flex: 1;
    }
    
    /* 模态框 */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 5% auto;
        padding: 1rem;
    }
    
    .number-pad {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .number-btn {
        height: 56px;
        font-size: 1.25rem;
    }

    /* ===== 游戏页面适配 ===== */
    
    .game-container {
        grid-template-rows: 50px 1fr 180px;
        grid-template-columns: 1fr 200px;
        gap: 0;
    }
    
    /* 顶部区域 */
    .game-header {
        padding: 0 0.5rem;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 0.875rem;
    }
    
    .room-code {
        font-size: 0.875rem;
    }
    
    .game-status {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    /* 中央游戏区域 */
    .game-main {
        padding: 0.25rem;
    }
    
    /* 玩家座位 - 简化显示 */
    .players-area {
        padding: 0.5rem;
    }
    
    .player-seat {
        transform: scale(0.85);
        transform-origin: center;
    }
    
    .player-avatar {
        width: 48px;
        height: 48px;
    }
    
    .player-name {
        font-size: 0.75rem;
        max-width: 80px;
    }
    
    .player-role {
        width: 36px;
        height: 48px;
    }
    
    /* 情报区 */
    .intel-area {
        gap: 0.25rem;
    }
    
    .intel-card {
        width: 40px;
        height: 56px;
    }
    
    /* 右侧信息区 */
    .game-info {
        padding: 0.5rem;
    }
    
    .timer-display {
        font-size: 2rem;
    }
    
    .game-log {
        max-height: 150px;
    }
    
    .log-entry {
        font-size: 0.75rem;
    }
    
    /* 底部玩家区域 */
    .player-area {
        padding: 0.5rem;
    }
    
    .my-avatar {
        width: 60px;
        height: 60px;
    }
    
    .my-role, .my-identity {
        width: 45px;
        height: 60px;
    }
    
    /* 手牌区域 - 横向滑动 */
    .hand-area {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding: 0.5rem 0;
    }
    
    .hand-area::-webkit-scrollbar {
        height: 4px;
    }
    
    .hand-area::-webkit-scrollbar-track {
        background: rgba(255,255,255,0.1);
        border-radius: 2px;
    }
    
    .hand-area::-webkit-scrollbar-thumb {
        background: var(--accent);
        border-radius: 2px;
    }
    
    .hand-card {
        flex: 0 0 auto;
        width: 60px;
        height: 84px;
        scroll-snap-align: center;
        margin-right: -20px; /* 卡牌重叠效果 */
    }
    
    .hand-card.selected {
        transform: translateY(-10px) scale(1.1);
        z-index: 10;
    }
    
    /* 操作按钮 */
    .action-area {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .action-btn {
        flex: 1 1 calc(50% - 0.5rem);
        min-height: 44px;
        font-size: 0.875rem;
        padding: 0.5rem;
    }
    
    /* 模态框优化 */
    .modal {
        align-items: flex-end;
    }
    
    .modal-content {
        width: 100%;
        max-height: 80vh;
        border-radius: 20px 20px 0 0;
        margin: 0;
        animation: slideUp 0.3s ease;
    }
    
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    .modal-header {
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .modal-body {
        padding: 1rem;
        max-height: 60vh;
        overflow-y: auto;
    }
    
    /* 玩家选择器 */
    .player-selector {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .selector-item {
        padding: 0.75rem;
    }
    
    /* 卡牌选择器 */
    .card-selector {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .selector-card {
        width: 80px;
        height: 112px;
    }
    
    /* 快捷聊天 */
    .quick-chat-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-radius: 20px 20px 0 0;
        padding: 1rem;
        z-index: 1000;
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }
    
    .quick-chat-panel.active {
        transform: translateY(0);
    }
    
    .quick-chat-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .quick-chat-btn {
        padding: 0.75rem;
        font-size: 0.875rem;
        border-radius: 8px;
        background: var(--bg-tertiary);
        border: none;
        color: var(--text-primary);
        min-height: 44px;
    }
    
    /* 提示信息 */
    .toast {
        left: 5%;
        right: 5%;
        max-width: none;
        text-align: center;
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }
}

/* ==================== 手机横屏 (小于1024px且横屏) ==================== */
@media (max-width: 1024px) and (orientation: landscape) {
    
    .game-container {
        grid-template-rows: 40px 1fr 140px;
    }
    
    .player-seat {
        transform: scale(0.75);
    }
    
    .hand-card {
        width: 50px;
        height: 70px;
    }
    
    .game-info {
        font-size: 0.75rem;
    }
    
    .timer-display {
        font-size: 1.5rem;
    }
}

/* ==================== 平板适配 (769px - 1024px) ==================== */
@media (min-width: 769px) and (max-width: 1024px) {
    
    .game-container {
        grid-template-columns: 1fr 240px;
    }
    
    .player-seat {
        transform: scale(0.9);
    }
    
    .modal-content {
        width: 80%;
    }
}

/* ==================== 触摸优化 ==================== */

/* 增大触摸目标 */
@media (pointer: coarse) {
    .btn,
    .btn-icon,
    .action-btn,
    .card,
    .avatar-item {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* 移除hover效果，使用active */
    .btn:hover,
    .card:hover {
        transform: none;
    }
    
    .btn:active,
    .card:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
    
    /* 禁用长按菜单 */
    img,
    .card,
    .avatar {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ==================== 安全区域适配 (刘海屏) ==================== */
@supports (padding-top: env(safe-area-inset-top)) {
    .game-header {
        padding-top: env(safe-area-inset-top);
    }
    
    .modal-content {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ==================== 深色模式优化 ==================== */
@media (prefers-color-scheme: dark) {
    :root {
        /* 保持原有深色主题 */
    }
}

/* ==================== 减少动画 (无障碍) ==================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== 游戏特定元素优化 ==================== */

/* 情报传递动画 - 简化版 */
@media (max-width: 768px) {
    .intel-passing-animation {
        transform: scale(0.7);
    }
    
    .passing-card {
        width: 60px;
        height: 84px;
    }
}

/* 角色技能提示 */
.skill-hint {
    position: fixed;
    bottom: 200px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    max-width: 90%;
    text-align: center;
    z-index: 100;
    animation: fadeInOut 3s ease;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    10%, 90% { opacity: 1; }
}

/* 当前玩家高亮 */
.current-turn-indicator {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: bold;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(233, 69, 96, 0.5);
}

/* 网络状态提示 */
.network-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f39c12;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.75rem;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.network-status.show {
    transform: translateY(0);
}

.network-status.offline {
    background: #e74c3c;
}
