/* ==================== CSS Custom Properties ==================== */
:root {
    --card-width: 70px;
    --card-height: 100px;
    --card-overlap: -30px;
    --card-font-size: 18px;
    --card-suit-size: 24px;
    --played-card-width: 50px;
    --played-card-height: 70px;
    --avatar-size: 50px;
    --top-bar-height: 50px;
    --tracker-height: 36px;
    --btn-action-padding: 12px 30px;
    --btn-action-font: 16px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-top: env(safe-area-inset-top, 0px);
}

/* ==================== Reset & Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* ==================== Game Container ==================== */
.game-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    overflow: hidden;
}

/* ==================== Top Bar ==================== */
.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    color: white;
    z-index: 100;
}

.game-title {
    font-size: 18px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.game-info {
    display: flex;
    gap: 12px;
    align-items: center;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
}

.btn {
    padding: 6px 14px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* ==================== Card Tracker (TOP horizontal bar) ==================== */
.card-tracker-bar {
    position: absolute;
    top: var(--top-bar-height);
    left: 0;
    right: 0;
    height: var(--tracker-height);
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    z-index: 99;
    overflow: hidden;
    transition: height 0.3s ease;
}

.card-tracker-bar.collapsed {
    height: var(--tracker-height);
}

.card-tracker-bar.expanded {
    height: auto;
    max-height: 100px;
}

.tracker-toggle {
    padding: 4px 12px;
    background: rgba(255, 215, 0, 0.2);
    color: #ffd700;
    border: none;
    border-radius: 0 10px 10px 0;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    min-height: 100%;
    display: flex;
    align-items: center;
    gap: 4px;
    -webkit-appearance: none;
    appearance: none;
}

.tracker-toggle:active {
    background: rgba(255, 215, 0, 0.4);
}

.tracker-toggle .arrow {
    transition: transform 0.3s;
    display: inline-block;
}

.card-tracker-bar.expanded .tracker-toggle .arrow {
    transform: rotate(180deg);
}

.tracker-content {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 10px;
    flex-wrap: wrap;
    overflow-x: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.card-tracker-bar.collapsed .tracker-content {
    display: none;
}

.tracker-item {
    text-align: center;
    padding: 2px 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    min-width: 32px;
    flex-shrink: 0;
}

.tracker-item.used {
    opacity: 0.3;
}

.tracker-value {
    font-size: 12px;
    font-weight: bold;
    color: white;
}

.tracker-count {
    font-size: 9px;
    color: #aaa;
}

/* ==================== Player Areas ==================== */
.player-area {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-bottom {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 800px;
}

.player-left {
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 130px;
    align-items: center;
}

.player-right {
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 130px;
    align-items: center;
}

/* ==================== Player Info ==================== */
.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 30px;
    margin-bottom: 8px;
}

.player-avatar {
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    border: 3px solid #ffd700;
    object-fit: cover;
    background: #333;
}

.player-name {
    color: white;
    font-size: 13px;
    font-weight: bold;
    white-space: nowrap;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.player-role {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e74c3c;
    color: white;
}

.player-role.farmer {
    background: #27ae60;
}

.card-count {
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}

/* ==================== Hand Cards (LEFT-ALIGNED fan layout) ==================== */
.hand-cards {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    min-height: calc(var(--card-height) + 30px);
    padding: 30px 10px 8px;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
}

.hand-cards::-webkit-scrollbar {
    display: none;
}

.card {
    width: var(--card-width);
    height: var(--card-height);
    min-width: var(--card-width);
    background: white;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 6px;
    font-size: var(--card-font-size);
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    margin-left: var(--card-overlap);
    flex-shrink: 0;
    -webkit-touch-callout: none;
}

.card:first-child {
    margin-left: 0;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.card.selected {
    transform: translateY(-20px);
    box-shadow: 0 12px 25px rgba(102, 126, 234, 0.5);
    border: 2px solid #667eea;
}

.card.red {
    color: #e74c3c;
}

.card.black {
    color: #2c3e50;
}

.card-value {
    font-size: var(--card-font-size);
    line-height: 1;
}

.card-suit {
    font-size: var(--card-suit-size);
    line-height: 1;
    margin-top: 1px;
}

/* 牌面中央大花色（装饰用） */
.card-center-suit {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--card-suit-size) * 1.8);
    opacity: 0.15;
    pointer-events: none;
}

.card.joker {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.card.joker.small {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
}

/* ==================== AI Card Backs ==================== */
.card-back {
    width: 40px;
    height: 60px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    border-radius: 5px;
    margin-left: -25px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.card-back:first-child {
    margin-left: 0;
}

.ai-cards {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 120px;
}

/* ==================== Play Area (Center) ==================== */
.play-area {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 90%;
    max-width: 500px;
}

.played-cards-container {
    display: flex;
    justify-content: space-around;
    width: 100%;
}

.played-cards {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.played-cards-label {
    color: white;
    font-size: 12px;
    margin-bottom: 5px;
}

.played-cards-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
    min-height: 70px;
}

.played-card {
    width: var(--played-card-width);
    height: var(--played-card-height);
    background: white;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.played-card.red {
    color: #e74c3c;
}

.played-card.black {
    color: #2c3e50;
}

/* ==================== Landlord Cards ==================== */
.landlord-cards {
    position: absolute;
    top: calc(var(--top-bar-height) + var(--tracker-height) + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 50;
}

.landlord-card {
    width: 45px;
    height: 65px;
    background: linear-gradient(135deg, #f39c12 0%, #e74c3c 100%);
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 12px;
}

.landlord-card.revealed {
    background: white;
    color: #333;
}

/* ==================== Action Buttons ==================== */
.action-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 2px;
    flex-wrap: wrap;
}

.btn-action {
    padding: 8px 24px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: bold;
    min-width: 44px;
    min-height: 36px;
    -webkit-appearance: none;
    appearance: none;
}

.btn-action:active {
    transform: scale(0.95);
}

.btn-play {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
}

.btn-pass {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
    color: white;
}

.btn-hint {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
}

.btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ==================== Bid Buttons ==================== */
.bid-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-bid {
    padding: 12px 25px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: bold;
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    color: white;
    min-width: 44px;
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}

.btn-bid:active {
    transform: scale(0.95);
}

.btn-nobid {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}

/* ==================== Multiplier ==================== */
.multiplier {
    position: absolute;
    top: calc(var(--top-bar-height) + var(--tracker-height) + 8px);
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 10px;
    padding: 8px 12px;
    color: white;
    font-size: 13px;
    z-index: 50;
}

.multiplier-value {
    color: #ffd700;
    font-weight: bold;
    font-size: 18px;
}

/* ==================== Toast Messages (bottom-left) ==================== */
.toast-container {
    position: absolute;
    bottom: 140px;
    left: 15px;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
    max-height: 200px;
    overflow: hidden;
}

.toast {
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 1.5s forwards;
    white-space: nowrap;
    border-left: 3px solid #ffd700;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(-30px); }
}

/* ==================== Result Modal ==================== */
.result-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.result-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    color: white;
    border: 2px solid #ffd700;
    min-width: 280px;
    max-width: 90vw;
}

.result-title {
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 15px;
}

.result-title.win { color: #2ecc71; }
.result-title.lose { color: #e74c3c; }

.result-score {
    font-size: 22px;
    margin-bottom: 15px;
}

.result-detail {
    font-size: 13px;
    color: #aaa;
    margin-bottom: 15px;
}

/* ==================== Leaderboard Modal ==================== */
.leaderboard-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.leaderboard-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    padding: 25px;
    color: white;
    border: 2px solid #ffd700;
    min-width: 350px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.leaderboard-title {
    font-size: 22px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 15px;
    color: #ffd700;
}

.leaderboard-list {
    max-height: 350px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 8px;
}

.leaderboard-item:nth-child(1) {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
}

.leaderboard-item:nth-child(2) {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}

.leaderboard-item:nth-child(3) {
    background: linear-gradient(135deg, #cd7f32 0%, #b8860b 100%);
}

.rank {
    font-weight: bold;
    width: 30px;
}

.player-name-lb {
    flex: 1;
    text-align: left;
    margin-left: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.lb-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.lb-stats {
    font-size: 12px;
    color: #aaa;
    margin-right: 10px;
}

.player-score {
    font-weight: bold;
    color: #ffd700;
}

.leaderboard-item.ai-item {
    opacity: 0.85;
    border-left: 3px solid #667eea;
}

/* ==================== Login Screen ==================== */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 20px;
}

.login-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 35px;
    min-width: 340px;
    max-width: 90vw;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.login-title {
    font-size: 26px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 8px;
    color: #333;
}

.login-subtitle {
    font-size: 13px;
    text-align: center;
    margin-bottom: 25px;
    color: #666;
}

.login-error {
    background: #fee;
    color: #c00;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    margin-bottom: 15px;
    display: none;
}

.login-error.show { display: block; }

.login-tip {
    background: #e8f4fd;
    color: #1976d2;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.login-tip strong {
    display: block;
    margin-bottom: 5px;
}

.btn-redirect-login {
    padding: 14px;
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: block;
    text-align: center;
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}

.btn-redirect-login:active {
    transform: scale(0.98);
}

.btn-guest {
    padding: 12px;
    background: transparent;
    color: #666;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
    min-height: 44px;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}

.btn-guest:active {
    background: #f5f5f5;
}

/* ==================== User Info ==================== */
.user-welcome {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-welcome-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.user-welcome-name {
    font-size: 13px;
    color: white;
    white-space: nowrap;
}

.btn-logout {
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.btn-logout:active {
    background: rgba(255, 255, 255, 0.3);
}

/* ==================== Loading ==================== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 15px;
    color: #666;
    font-size: 14px;
}

/* ==================== Hidden ==================== */
.hidden {
    display: none !important;
}

/* ============================================================
   MOBILE RESPONSIVE - 全面优化手机端体验
   ============================================================ */

/* 手机端基础设置 */
@media (max-width: 768px) {
    :root {
        --card-width: 48px;
        --card-height: 70px;
        --card-overlap: -26px;
        --card-font-size: 13px;
        --card-suit-size: 16px;
        --played-card-width: 36px;
        --played-card-height: 52px;
        --avatar-size: 32px;
        --top-bar-height: 44px;
        --tracker-height: 28px;
        --btn-action-padding: 10px 18px;
        --btn-action-font: 14px;
    }

    /* 顶部栏简化 */
    .top-bar {
        padding: 0 8px;
    }

    .game-title {
        font-size: 14px;
    }

    .game-info {
        gap: 6px;
    }

    .info-item {
        font-size: 11px;
    }

    .btn {
        padding: 4px 8px;
        font-size: 11px;
    }

    .user-welcome-name {
        display: none;
    }

    /* 记牌器 */
    .card-tracker-bar {
        height: var(--tracker-height);
    }

    .tracker-toggle {
        padding: 3px 8px;
        font-size: 11px;
    }

    .tracker-item {
        min-width: 24px;
        padding: 2px 3px;
    }

    .tracker-value {
        font-size: 10px;
    }

    .tracker-count {
        font-size: 7px;
    }

    /* AI玩家位置调整 - 更紧凑 */
    .player-left {
        left: 5px;
        top: 35%;
        transform: translateY(-50%);
    }

    .player-right {
        right: 5px;
        top: 35%;
        transform: translateY(-50%);
    }

    .player-info {
        gap: 4px;
        padding: 4px 8px;
        margin-bottom: 4px;
        font-size: 10px;
    }

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

    .player-role {
        font-size: 9px;
        padding: 1px 5px;
    }

    .card-count {
        font-size: 10px;
        padding: 1px 5px;
    }

    /* AI手牌背面 */
    .card-back {
        width: 28px;
        height: 42px;
        margin-left: -18px;
    }

    .ai-cards {
        max-width: 80px;
    }

    /* 中央出牌区域 */
    .play-area {
        top: 42%;
        gap: 10px;
    }

    .played-cards-container {
        width: 100%;
    }

    .played-cards {
        min-width: 70px;
    }

    .played-cards-list {
        min-height: 55px;
        gap: 2px;
    }

    /* 底牌和倍数 */
    .landlord-cards {
        top: calc(var(--top-bar-height) + var(--tracker-height) + 5px);
        gap: 4px;
    }

    .landlord-card {
        width: 32px;
        height: 46px;
        font-size: 9px;
    }

    .multiplier {
        top: calc(var(--top-bar-height) + var(--tracker-height) + 5px);
        right: 8px;
        padding: 4px 8px;
        font-size: 10px;
    }

    .multiplier-value {
        font-size: 14px;
    }

    /* 玩家底部区域 */
    .player-bottom {
        width: 98%;
        bottom: 0;
    }

    .player-info {
        margin-bottom: 2px;
    }

    .hand-cards {
        min-height: calc(var(--card-height) + 25px);
        padding: 25px 5px 2px;
    }

    /* 操作按钮 - 紧凑 */
    .action-buttons {
        gap: 6px;
        margin-top: 1px;
    }

    .btn-action {
        padding: 5px 14px;
        font-size: 12px;
        min-height: 32px;
    }

    .bid-buttons {
        gap: 6px;
    }

    .btn-bid {
        padding: 5px 14px;
        font-size: 12px;
        min-height: 32px;
    }

    .bid-buttons {
        gap: 8px;
    }

    .btn-bid {
        padding: 8px 16px;
        font-size: 13px;
        min-height: 40px;
    }

    /* Toast消息 */
    .toast-container {
        bottom: 100px;
        left: 8px;
    }

    .toast {
        font-size: 11px;
        padding: 5px 10px;
    }

    /* 弹窗 */
    .login-container {
        min-width: auto;
        width: 90%;
        padding: 20px 15px;
    }

    .login-title {
        font-size: 20px;
    }

    .login-subtitle {
        font-size: 12px;
        margin-bottom: 15px;
    }

    .login-tip {
        padding: 10px;
        font-size: 12px;
        margin-bottom: 15px;
    }

    .result-content {
        padding: 20px;
        min-width: 240px;
    }

    .result-title {
        font-size: 24px;
    }

    .result-score {
        font-size: 18px;
    }

    .leaderboard-content {
        min-width: auto;
        width: 90%;
        padding: 15px;
    }

    .leaderboard-title {
        font-size: 18px;
    }

    .leaderboard-item {
        padding: 8px 10px;
        margin-bottom: 6px;
        font-size: 12px;
    }
}

/* 小屏手机 (iPhone SE, 小米等) */
@media (max-width: 400px) {
    :root {
        --card-width: 42px;
        --card-height: 62px;
        --card-overlap: -22px;
        --card-font-size: 11px;
        --card-suit-size: 14px;
        --played-card-width: 30px;
        --played-card-height: 44px;
        --avatar-size: 28px;
        --top-bar-height: 40px;
        --tracker-height: 24px;
    }

    .game-title {
        font-size: 12px;
    }

    .game-info {
        gap: 4px;
    }

    .btn {
        padding: 3px 6px;
        font-size: 10px;
    }

    .player-info {
        padding: 3px 6px;
        gap: 3px;
    }

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

    .player-role {
        font-size: 8px;
        padding: 1px 4px;
    }

    .card-back {
        width: 24px;
        height: 36px;
        margin-left: -15px;
    }

    .ai-cards {
        max-width: 60px;
    }

    .btn-action {
        padding: 6px 12px;
        font-size: 12px;
        min-height: 36px;
    }

    .btn-bid {
        padding: 6px 12px;
        font-size: 12px;
        min-height: 36px;
    }

    .landlord-card {
        width: 28px;
        height: 40px;
        font-size: 8px;
    }

    .multiplier {
        padding: 3px 6px;
        font-size: 9px;
    }

    .multiplier-value {
        font-size: 12px;
    }

    .toast-container {
        bottom: 85px;
    }

    .toast {
        font-size: 10px;
        padding: 4px 8px;
    }
}

/* 横屏手机 */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --card-width: 44px;
        --card-height: 64px;
        --card-overlap: -18px;
        --card-font-size: 11px;
        --card-suit-size: 14px;
        --top-bar-height: 36px;
        --tracker-height: 24px;
        --avatar-size: 28px;
    }

    .game-title {
        font-size: 12px;
    }

    .game-info {
        gap: 4px;
    }

    .btn {
        padding: 3px 6px;
        font-size: 10px;
    }

    .user-welcome-name {
        display: none;
    }

    /* 横屏时AI玩家移到两侧中间 */
    .player-left {
        left: 5px;
        top: 50%;
    }

    .player-right {
        right: 5px;
        top: 50%;
    }

    .player-info {
        flex-direction: column;
        padding: 4px 6px;
        gap: 2px;
    }

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

    .card-back {
        width: 22px;
        height: 34px;
        margin-left: -14px;
    }

    .ai-cards {
        max-width: 50px;
    }

    /* 中央区域 */
    .play-area {
        top: 48%;
        gap: 5px;
    }

    .played-cards-list {
        min-height: 45px;
    }

    /* 底部玩家 */
    .player-bottom {
        bottom: 3px;
    }

    .hand-cards {
        min-height: calc(var(--card-height) + 20px);
    }

    /* 底牌 */
    .landlord-cards {
        left: 10px;
        top: calc(var(--top-bar-height) + var(--tracker-height) + 5px);
        transform: none;
    }

    .landlord-card {
        width: 26px;
        height: 38px;
        font-size: 8px;
    }

    .multiplier {
        right: auto;
        left: auto;
        right: 10px;
    }

    /* 按钮 */
    .action-buttons {
        gap: 6px;
        margin-top: 3px;
    }

    .btn-action {
        padding: 5px 12px;
        font-size: 11px;
        min-height: 32px;
    }

    .bid-buttons {
        gap: 6px;
    }

    .btn-bid {
        padding: 5px 12px;
        font-size: 11px;
        min-height: 32px;
    }

    /* Toast */
    .toast-container {
        bottom: 75px;
    }

    /* 记牌器 */
    .tracker-toggle {
        padding: 2px 6px;
        font-size: 10px;
    }

    .tracker-item {
        min-width: 20px;
        padding: 1px 2px;
    }

    .tracker-value {
        font-size: 9px;
    }

    .tracker-count {
        font-size: 6px;
    }
}

/* 超小屏幕 (iPhone 5/SE 第一代等) */
@media (max-width: 360px) {
    :root {
        --card-width: 38px;
        --card-height: 56px;
        --card-overlap: -20px;
        --card-font-size: 10px;
        --card-suit-size: 12px;
        --played-card-width: 26px;
        --played-card-height: 38px;
    }

    .game-title {
        font-size: 11px;
    }

    .btn {
        padding: 2px 5px;
        font-size: 9px;
    }

    .player-info {
        padding: 2px 4px;
    }

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

    .card-back {
        width: 20px;
        height: 30px;
        margin-left: -12px;
    }

    .btn-action {
        padding: 5px 10px;
        font-size: 11px;
    }

    .btn-bid {
        padding: 5px 10px;
        font-size: 11px;
    }
}

/* 高端手机 (iPhone X+, 带刘海) */
@media (min-width: 375px) and (min-height: 812px) {
    .player-bottom {
        bottom: calc(10px + var(--safe-area-bottom));
    }

    .top-bar {
        padding-top: var(--safe-area-top);
        height: calc(var(--top-bar-height) + var(--safe-area-top));
    }

    .card-tracker-bar {
        top: calc(var(--top-bar-height) + var(--safe-area-top));
    }

    .landlord-cards {
        top: calc(var(--top-bar-height) + var(--tracker-height) + var(--safe-area-top) + 8px);
    }

    .multiplier {
        top: calc(var(--top-bar-height) + var(--tracker-height) + var(--safe-area-top) + 8px);
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .card:hover {
        transform: none;
    }

    .card:active {
        transform: translateY(-5px);
    }

    .card.selected:active {
        transform: translateY(-20px);
    }

    .btn:hover,
    .btn-action:hover,
    .btn-bid:hover {
        transform: none;
    }

    .btn:active,
    .btn-action:active,
    .btn-bid:active {
        transform: scale(0.95);
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    .login-container {
        background: rgba(30, 30, 40, 0.95);
    }

    .login-title {
        color: #ffd700;
    }

    .login-subtitle {
        color: #aaa;
    }

    .login-tip {
        background: rgba(100, 150, 200, 0.2);
        color: #8cb4d8;
    }

    .btn-guest {
        color: #aaa;
        border-color: #444;
    }
}
