/* 掼蛋游戏样式 - 手机/平板/电脑自适应 v3 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: linear-gradient(135deg, #1a472a 0%, #2d5a3f 50%, #1a472a 100%);
    min-height: 100vh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

#game-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* 战绩 */
#score-info {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.55);
    color: #f1c40f;
    font-size: 12px;
    font-weight: bold;
    padding: 3px 14px;
    border-radius: 12px;
    z-index: 60;
    white-space: nowrap;
    pointer-events: none;
}

/* 玩家信息 */
.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 13px;
    flex-shrink: 0;
    min-height: 32px;
}

.player-info .name {
    font-weight: bold;
}

.player-info .level {
    background: #e74c3c;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
}

.player-info .count {
    background: rgba(255, 255, 255, 0.18);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
}

.player-info .count.alert {
    background: #e74c3c;
    font-weight: bold;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.side-player .count {
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 11px;
    padding: 2px 0;
}

.side-player .count.alert {
    color: #ff6b6b;
    font-weight: bold;
}

/* 手牌区域通用 */
.hand-cards {
    display: flex;
    align-items: flex-end;
    padding: 6px 4px;
    min-height: 40px;
    overflow: hidden;
}

/* 自己手牌：横向滚动 + 重叠 */
#hand-self {
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 14px 8px 18px;
    min-height: 118px;
    gap: 0;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    scrollbar-width: none;
}
#hand-self::-webkit-scrollbar {
    display: none;
}

#hand-self .card {
    margin-left: -12px;
    flex-shrink: 0;
}
#hand-self .card:first-child {
    margin-left: 0;
}

/* 对手A 手牌（上方小卡背） */
#hand-top {
    flex-wrap: nowrap;
    justify-content: center;
    min-height: 30px;
    max-height: 32px;
    padding: 3px 8px;
}

/* 侧边对手手牌（竖排小卡背） */
.side-player .hand-cards {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 0;
    max-height: 108px;
    padding: 4px 2px;
    gap: 1px;
}

/* 牌面样式 */
.card {
    width: 52px;
    height: 73px;
    background: white;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4px;
    font-size: 13px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s;
    position: relative;
    border: 2px solid transparent;
    flex-shrink: 0;
}

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

.card.selected {
    border-color: #f1c40f;
    transform: translateY(-18px) !important;
    box-shadow: 0 4px 14px rgba(241, 196, 15, 0.7);
    z-index: 20;
}

/* 逢人配（红桃级牌·万能牌）特殊样式 */
.card.wild {
    background: linear-gradient(135deg, #fff7e0, #ffe9b3);
    border-color: #f39c12;
}
.card.wild .wild-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f39c12;
    color: white;
    font-size: 9px;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 6px;
    z-index: 5;
}

.card .suit-top {
    align-self: flex-start;
    font-size: 14px;
    line-height: 1;
}

.card .value-center {
    align-self: center;
    font-size: 18px;
    line-height: 1;
}

.card .suit-bottom {
    align-self: flex-end;
    font-size: 14px;
    transform: rotate(180deg);
    line-height: 1;
}

.card.red { color: #e74c3c; }
.card.black { color: #2c3e50; }
.card.joker-red { color: #e74c3c; }
.card.joker-black { color: #2c3e50; }

/* 对手手牌（背面） */
.card-back {
    width: 16px;
    height: 24px;
    background: linear-gradient(135deg, #3498db, #2980b9);
    border-radius: 3px;
    border: 1px solid white;
    margin: 1px;
    flex-shrink: 0;
}

/* 中间出牌区 */
#play-area {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    padding: 0 8px;
    min-height: 0;
}

.side-player {
    width: 64px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

#center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 8px 4px;
}

#last-played {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 3px;
    min-height: 66px;
    max-height: 100px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    margin-bottom: 6px;
    width: 100%;
    overflow-y: auto;
}

.last-label {
    width: 100%;
    text-align: center;
    color: #f1c40f;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 2px;
}

#last-played .card {
    width: 34px;
    height: 48px;
    font-size: 10px;
    padding: 2px;
    border-radius: 4px;
    cursor: default;
}
#last-played .card .value-center { font-size: 13px; }
#last-played .card .suit-top,
#last-played .card .suit-bottom { font-size: 11px; }

#message {
    color: white;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    padding: 7px 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    margin-bottom: 6px;
    min-height: 34px;
    width: 100%;
    line-height: 1.4;
}

/* 按钮样式 */
#controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

#btn-pass { background: #95a5a6; color: white; }
#btn-play { background: #27ae60; color: white; }
#btn-sort { background: #3498db; color: white; }

.btn:active {
    transform: scale(0.95);
    opacity: 0.85;
}
.btn.hidden { display: none; }
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal.hidden { display: none; }

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    max-width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.modal-content h2 {
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 20px;
}
.modal-content p {
    color: #7f8c8d;
    margin-bottom: 15px;
    font-size: 14px;
}

/* 进贡选牌弹窗 */
#tribute-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 15px;
    padding: 8px;
}
#tribute-cards .card.selected {
    transform: translateY(-14px) !important;
}
#tribute-modal .btn:disabled {
    opacity: 0.5;
}

/* 玩家区域 */
#opponents {
    padding-top: 26px;
    flex-shrink: 0;
}

#player-self {
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    padding-bottom: 4px;
}

/* ============ 手机竖屏（默认）小尺寸 ============ */
@media (max-width: 380px) {
    .card {
        width: 46px;
        height: 65px;
        font-size: 11px;
        padding: 3px;
    }
    #hand-self .card { margin-left: -10px; }
    .card .value-center { font-size: 16px; }
    .card .suit-top,
    .card .suit-bottom { font-size: 12px; }
    #hand-self { min-height: 108px; }
    #last-played .card { width: 30px; height: 42px; }
}

/* ============ 横屏手机 / 平板 ============ */
@media (min-width: 700px) and (orientation: landscape), (min-width: 900px) and (orientation: portrait) {
    .card {
        width: 62px;
        height: 87px;
        font-size: 15px;
    }
    #hand-self .card { margin-left: -12px; }
    #hand-self { min-height: 140px; }
    .card .value-center { font-size: 22px; }
    .card .suit-top,
    .card .suit-bottom { font-size: 16px; }
    #last-played .card { width: 46px; height: 64px; }
    #last-played .card .value-center { font-size: 18px; }
    #last-played .card .suit-top,
    #last-played .card .suit-bottom { font-size: 14px; }
    #hand-top { max-height: 40px; }
    .card-back { width: 20px; height: 30px; }
    .side-player { width: 90px; }
    .player-info { font-size: 14px; padding: 8px 14px; }
    #message { font-size: 16px; }
    .btn { padding: 12px 28px; font-size: 15px; }
}

/* ============ 电脑 / 大屏 ============ */
@media (min-width: 1100px) {
    #score-info {
        font-size: 14px;
        padding: 5px 20px;
        top: 8px;
    }
    .card {
        width: 78px;
        height: 109px;
        font-size: 18px;
        border-radius: 9px;
        padding: 6px;
    }
    #hand-self .card { margin-left: -36px; }
    #hand-self { min-height: 185px; padding: 20px 16px 24px; }
    #hand-self .card.selected { transform: translateY(-24px) !important; }
    .card .value-center { font-size: 30px; }
    .card .suit-top,
    .card .suit-bottom { font-size: 22px; }
    #last-played {
        min-height: 100px;
        max-height: 150px;
        padding: 12px;
        gap: 6px;
        margin-bottom: 12px;
    }
    #last-played .card {
        width: 62px;
        height: 87px;
        font-size: 14px;
        padding: 4px;
    }
    #last-played .card .value-center { font-size: 24px; }
    #last-played .card .suit-top,
    #last-played .card .suit-bottom { font-size: 18px; }
    .last-label { font-size: 15px; margin-bottom: 6px; }
    #message {
        font-size: 18px;
        padding: 12px 16px;
        min-height: 44px;
        margin-bottom: 12px;
    }
    #controls { gap: 14px; }
    .btn {
        padding: 14px 40px;
        font-size: 17px;
        border-radius: 24px;
    }
    .side-player { width: 140px; }
    .side-player .hand-cards { max-height: 150px; gap: 3px; }
    .card-back { width: 26px; height: 38px; border-radius: 5px; }
    #hand-top { max-height: 52px; min-height: 48px; padding: 6px 16px; }
    #opponents { padding-top: 34px; }
    #hand-self::-webkit-scrollbar {
        display: block;
        height: 8px;
    }
    #hand-self::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 4px;
    }
    #hand-self::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.2);
    }
    .player-info {
        font-size: 15px;
        padding: 10px 18px;
        min-height: 42px;
    }
    .player-info .level { font-size: 13px; padding: 3px 12px; }
    .player-info .count { font-size: 13px; padding: 3px 12px; }
    .modal-content { padding: 35px 45px; }
    .modal-content h2 { font-size: 26px; }
    .modal-content p { font-size: 16px; }
    #tribute-cards { max-height: 320px; gap: 6px; }
    #tribute-cards .card { width: 70px; height: 98px; }
    #tribute-cards .card .value-center { font-size: 28px; }
    #tribute-cards .card .suit-top,
    #tribute-cards .card .suit-bottom { font-size: 20px; }
}
