/* ============ 桌面自适应 ============ */

/* 基础桌面自适应 - 使用 clamp 实现流体尺寸 */
.game-main {
    padding: clamp(16px, 2vw, 32px);
    gap: clamp(16px, 2vw, 28px);
}

.game-header {
    padding: clamp(12px, 1.5vw, 20px) clamp(16px, 2vw, 32px);
}

.logo {
    font-size: clamp(1.2rem, 2vw, 1.6rem);
}

.market-value {
    font-size: clamp(16px, 1.5vw, 20px);
}

.player-card {
    padding: clamp(12px, 1.5vw, 20px);
}

.mini-card {
    min-width: clamp(60px, 8vw, 90px);
    min-height: clamp(70px, 9vw, 100px);
    font-size: clamp(8px, 1vw, 11px);
}

.my-positions,
.my-played-cards {
    padding: clamp(14px, 1.5vw, 24px);
}

.game-messages {
    padding: 12px;
}

.positions-grid {
    gap: clamp(8px, 1vw, 14px);
}

.card {
    min-width: clamp(100px, 10vw, 140px);
    height: clamp(140px, 14vw, 190px);
    padding: clamp(10px, 1vw, 14px);
}

.card-name {
    font-size: clamp(12px, 1.2vw, 15px);
}

.hand-area {
    padding: clamp(14px, 1.5vw, 24px);
    gap: clamp(16px, 2vw, 28px);
}

.hand-cards {
    gap: clamp(10px, 1vw, 14px);
}

.btn {
    padding: clamp(10px, 1vw, 14px) clamp(16px, 1.5vw, 28px);
    font-size: clamp(14px, 1.2vw, 16px);
}

.my-stats {
    padding: 6px 12px;
}

.stat-value {
    font-size: clamp(18px, 1.5vw, 20px);
}

/* 超大屏幕优化 */
@media (min-width: 1600px) {
    .game-main {
        grid-template-columns: 1fr 2.5fr 1fr;
        max-width: 1800px;
        margin: 0 auto;
    }

    .positions-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .card {
        min-width: 150px;
        height: 210px;
    }

    .mini-card {
        min-width: 100px;
        min-height: 110px;
        font-size: 12px;
    }
}

/* 大屏幕 */
@media (min-width: 1280px) and (max-width: 1599px) {
    .game-main {
        grid-template-columns: 1fr 2fr 1fr;
    }

    .positions-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 中等屏幕 */
@media (min-width: 1024px) and (max-width: 1279px) {
    .game-main {
        grid-template-columns: 280px 1fr 250px;
    }

    .positions-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .mini-card {
        min-width: 70px;
        min-height: 80px;
    }

    .card {
        min-width: 110px;
        height: 154px;
    }
}


/* 模态框桌面自适应 */
.modal-content {
    max-width: min(600px, 90vw);
}

.overlay-content {
    max-width: min(400px, 90vw);
}

/* 登录页面桌面自适应 */
.login-card {
    max-width: min(420px, 90vw);
    padding: clamp(32px, 4vw, 56px);
}

.game-title {
    font-size: clamp(1.75rem, 3.5vw, 2.75rem);
}

.game-subtitle {
    font-size: clamp(1rem, 1.5vw, 1.3rem);
}

/* ============ 响应式 ============ */


/* 平板尺寸 */
@media (max-width: 1024px) {
    .game-main {
        grid-template-columns: 1fr;
        padding: 16px;
        gap: 16px;
    }

    .other-players {
        flex-direction: row;
        flex-wrap: wrap;
        order: 2;
    }

    .center-area {
        order: 1;
    }

    .my-info {
        order: 3;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .player-card {
        flex: 1 1 200px;
    }

    .my-stats {
        flex: 1 1 150px;
    }
}

/* 手机尺寸 */
@media (max-width: 640px) {

    /* 单一卷轴 - 移除多个滚动区域 */
    .game-container {
        height: auto;
        max-height: none;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .game-main {
        display: flex;
        flex-direction: column;
        overflow: visible;
        min-height: auto;
        gap: 12px;
    }

    /* 確保區塊順序正確 */
    .center-area {
        order: 1;
        overflow: visible;
    }

    .other-players {
        order: 2;
        overflow: visible;
        max-height: none;
    }

    .my-info {
        order: 3;
        overflow: visible;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .my-stats {
        overflow: visible;
    }

    .live-chat {
        overflow: visible;
        min-height: 130px;
    }

    .chat-messages {
        max-height: 80px;
        min-height: 50px;
        overflow-y: auto;
    }

    /* 事件廣播 - 固定高度防止溢出 */
    .game-messages {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        max-height: 160px !important;
        min-height: 80px;
        position: relative;
        z-index: 1;
        flex-shrink: 0;
    }

    /* 登录页面 */
    .login-container {
        padding: 16px;
    }

    .login-card {
        padding: 24px 20px;
        border-radius: 12px;
    }

    .game-title {
        font-size: 1.75rem;
    }

    .game-subtitle {
        font-size: 1rem;
        margin-bottom: 24px;
    }

    .login-form input {
        padding: 12px 14px;
        font-size: 16px;
        /* 防止 iOS 缩放 */
    }

    .btn {
        padding: 14px 20px;
        font-size: 16px;
        min-height: 48px;
        /* 更好的触控目标 */
    }

    /* 游戏页头部 */
    .game-header {
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 12px;
    }

    .header-left {
        gap: 12px;
        width: 100%;
        justify-content: space-between;
    }

    .logo {
        font-size: 1.2rem;
    }

    .round-info {
        font-size: 14px;
    }

    .header-center {
        width: 100%;
        order: 3;
    }

    .market-info {
        width: 100%;
        justify-content: space-around;
        padding: 10px 12px;
        gap: 12px;
    }

    .market-label {
        font-size: 11px;
    }

    .market-value {
        font-size: 16px;
    }

    .header-right {
        order: 2;
    }

    #current-turn {
        padding: 6px 12px;

        font-size: 13px;
    }

    /* 主游戏区域 */
    .game-main {
        padding: 12px;
        gap: 12px;
    }

    .other-players {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .player-card {
        padding: 14px;
        border-radius: 10px;
        overflow: visible;
    }

    .player-header {
        margin-bottom: 10px;
    }

    .player-name {
        font-size: 16px;
    }

    .player-hp {
        font-size: 14px;
        padding: 4px 10px;
    }

    .player-stats {
        font-size: 13px;
        gap: 12px;
        padding: 8px 0;
    }

    .player-positions {
        gap: 6px;
        margin-top: 8px;
    }

    .mini-card {
        min-width: 70px;
        min-height: 85px;
        font-size: 10px;
        padding: 6px;
        border-radius: 6px;
    }

    /* 中央区域 */
    .center-area {
        gap: 12px;
    }

    .my-positions,
    .my-played-cards,
    .game-messages {
        padding: 14px;
        border-radius: 10px;
    }

    .my-positions h3,
    .my-played-cards h3 {
        font-size: 13px;
        margin-bottom: 12px;
    }

    .positions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        min-height: 100px;
    }

    .position-slot {
        font-size: 10px;
        min-height: 160px;
        height: 160px;
    }

    .played-cards-grid {
        gap: 8px;
        min-height: 40px;
    }

    .played-card-mini {
        padding: 6px 10px;
        font-size: 11px;
    }

    .game-messages {
        grid-column: 1 / -1;
        max-height: 180px;
        min-height: 100px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .message {
        padding: 10px 12px;
        font-size: 14px;
        margin-bottom: 8px;
    }

    /* 我的信息 */
    .my-stats {
        padding: 14px;
        border-radius: 10px;
    }

    .stat {
        padding: 8px 0;
    }

    .stat-label {
        font-size: 15px;
    }

    .stat-value {
        font-size: 22px;
    }

    /* 手牌区域 */
    .hand-area {
        flex-direction: column;
        padding: 14px;
        gap: 14px;
    }

    .hand-cards {
        width: 100%;
        gap: 10px;
        padding: 8px 0;
        -webkit-overflow-scrolling: touch;
        /* iOS 滚动优化 */
    }

    .card {
        min-width: 100px;
        height: 140px;
        padding: 10px;
        border-radius: 8px;
        flex-shrink: 0;
    }

    .card-type {
        font-size: 9px;
        margin-bottom: 6px;
    }

    .card-name {
        font-size: 12px;
    }

    .card-stats {
        font-size: 10px;
    }

    .card-actions button {
        padding: 8px;
        font-size: 10px;
        min-height: 32px;
    }

    .action-buttons {
        flex-direction: row;
        width: 100%;
        gap: 10px;
    }

    .action-buttons .btn {
        flex: 1;
    }

    /* 覆盖层和模态框 */
    .overlay-content {
        padding: 24px;
        margin: 16px;
        max-width: calc(100% - 32px);
    }

    .overlay-content h2 {
        font-size: 1.25rem;
        margin-bottom: 12px;
    }

    .overlay-content p {
        font-size: 14px;
    }

    .modal-content {
        padding: 20px;
        margin: 16px;
        max-width: calc(100% - 32px);
        max-height: calc(100vh - 32px);
        border-radius: 12px;
    }

    .modal-content h2 {
        font-size: 1.25rem;
        margin-bottom: 16px;
    }

    .settlement-section {
        padding: 12px;
        margin-bottom: 12px;
    }

    .settlement-section h4 {
        font-size: 13px;
        margin-bottom: 8px;
    }

    /* 功能鏈接區域 - 遊戲說明書和排行榜按鈕置中 */
    .login-card .btn {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        text-align: center !important;
    }

    /* 排行榜彈窗樣式 */
    .leaderboard-modal-body {
        padding: 0;
    }

    .leaderboard-modal-body .leaderboard-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
        max-height: 50vh;
        overflow-y: auto;
    }

    .leaderboard-modal-body .leaderboard-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 12px;
        background: rgba(15, 23, 42, 0.5);
        border-radius: 8px;
        transition: all 0.2s ease;
    }

    .leaderboard-modal-body .leaderboard-item:hover {
        background: rgba(99, 102, 241, 0.1);
    }

    .leaderboard-modal-body .leaderboard-item.top-1 {
        background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.1));
        border: 1px solid rgba(251, 191, 36, 0.2);
    }

    .leaderboard-modal-body .leaderboard-item.top-2 {
        background: linear-gradient(135deg, rgba(156, 163, 175, 0.15), rgba(107, 114, 128, 0.1));
        border: 1px solid rgba(156, 163, 175, 0.2);
    }

    .leaderboard-modal-body .leaderboard-item.top-3 {
        background: linear-gradient(135deg, rgba(180, 83, 9, 0.15), rgba(146, 64, 14, 0.1));
        border: 1px solid rgba(180, 83, 9, 0.2);
    }

    .leaderboard-modal-body .leaderboard-rank {
        font-size: 14px;
        font-weight: 700;
        color: var(--text-secondary);
        min-width: 24px;
    }

    .leaderboard-modal-body .leaderboard-item.top-1 .leaderboard-rank {
        color: #fbbf24;
    }

    .leaderboard-modal-body .leaderboard-item.top-2 .leaderboard-rank {
        color: #9ca3af;
    }

    .leaderboard-modal-body .leaderboard-item.top-3 .leaderboard-rank {
        color: #b45309;
    }

    .leaderboard-modal-body .leaderboard-username {
        flex: 1;
        font-size: 14px;
        font-weight: 500;
        color: var(--text-primary);
        margin-left: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .leaderboard-modal-body .leaderboard-glvc {
        font-size: 13px;
        font-weight: 700;
        color: #a78bfa;
        background: rgba(167, 139, 250, 0.1);
        padding: 3px 10px;
        border-radius: 12px;
    }

    .leaderboard-modal-body .leaderboard-empty,
    .leaderboard-modal-body .leaderboard-loading {
        text-align: center;
        color: var(--text-secondary);
        font-size: 14px;
        padding: 24px 0;
        list-style: none;
    }

    .leaderboard-modal-body .leaderboard-pagination {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 12px;
        margin-top: 16px;
        padding-top: 12px;
        border-top: 1px solid rgba(99, 102, 241, 0.15);
    }
}

/* 极小手机尺寸 */
@media (max-width: 375px) {
    .game-title {
        font-size: 1.5rem;
    }

    .login-card {
        padding: 20px 16px;
    }

    .other-players {
        grid-template-columns: 1fr;
    }

    .positions-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .card {
        min-width: 90px;
        height: 126px;
    }

    .market-info {
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* 横向手机 */
@media (max-height: 500px) and (orientation: landscape) {
    .game-container {
        min-height: auto;
    }

    .game-main {
        grid-template-columns: 1fr 2fr;
        max-height: 50vh;
    }

    .hand-area {
        flex-direction: row;
        padding: 10px;
    }

    .card {
        height: 120px;
        min-width: 85px;
    }

    .other-players {
        flex-direction: column;
        max-height: 45vh;
        overflow-y: auto;
    }
}

/* iOS 底部安全区域 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .hand-area {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
}

/* 响应式右侧栏聊天室 */
@media (max-width: 768px) {
    .community-links {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .community-link {
        flex: 1;
        min-width: 140px;
        justify-content: center;
        font-size: 11px;
        padding: 8px 10px;
    }

    .live-chat {
        min-height: 140px;
        overflow: visible;
    }

    .live-chat h3 {
        font-size: 14px;
    }

    .chat-messages {
        max-height: 100px;
        min-height: 60px;
    }

    .chat-message {
        font-size: 13px;
        padding: 8px 12px;
    }

    .chat-input-area {
        flex-wrap: nowrap;
    }

    .chat-input-area input {
        font-size: 14px;
        padding: 10px 12px;
        min-width: 0;
    }

    .chat-input-area button {
        font-size: 13px;
        padding: 10px 14px;
        white-space: nowrap;
    }

    /* 我的信息區域 - 手機端並排 */
    .my-info {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        overflow: visible;
    }

    .my-stats {
        overflow: visible;
    }

    .game-messages {
        grid-column: 1 / -1;
    }
}