/* 拖拉机（双升）样式 - 手机/平板/电脑自适应 v1（视觉体系参照站内掼蛋） */
* {
    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;
}

/* 版本标识（右下角小字，核对刷新用） */
#ver-tag {
    position: fixed;
    right: 4px;
    bottom: 3px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    z-index: 5;
    pointer-events: none;
    font-weight: bold;
}

/* 顶部比分 */
#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: 4px 10px;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 12px;
    flex-shrink: 0;
    min-height: 28px;
    gap: 6px;
}

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

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

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

.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: 4px 4px;
    min-height: 36px;
    overflow: hidden;
}

/* 自己手牌：多行自动换行平铺（一屏看全，不滑动） */
#hand-self {
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    overflow: visible;
    padding: 10px 6px 14px;
    min-height: 100px;
    gap: 4px 0;
    touch-action: manipulation;
}

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

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

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

/* 牌面样式 */
.card {
    width: 48px;
    height: 68px;
    background: white;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4px;
    font-size: 12px;
    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(-16px) !important;
    box-shadow: 0 4px 14px rgba(241, 196, 15, 0.7);
    z-index: 20;
}

/* 亮主相关的牌（高亮提示） */
.card.can-declare {
    box-shadow: 0 0 10px 3px rgba(241, 196, 15, 0.9);
}

/* 已亮出/正在亮的主牌 */
.card.lit {
    border-color: #ffd700;
    box-shadow: 0 0 12px 4px rgba(255, 215, 0, 0.85);
}

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

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

.card .suit-bottom {
    align-self: flex-end;
    font-size: 13px;
    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.trump-card {
    background: linear-gradient(135deg, #fffbeb, #ffeecb);
}

/* 发牌飞入动画 */
@keyframes dealIn {
    from { transform: translateY(-26px) scale(0.6); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}
.card.dealt {
    animation: dealIn 0.28s ease-out;
}

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

.card-back.dealt {
    animation: dealIn 0.28s ease-out;
}

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

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

#center-area {
    flex: 1;
    min-width: 0;   /* ★ 允许收缩：防止内容撑爆屏幕（修复手机右侧不可见，2026-09-11） */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
    padding: 2px 4px;
    overflow: hidden;
}

/* 亮主信息条 */
#trump-bar {
    width: 100%;
    text-align: center;
    color: #f1c40f;
    font-size: 12px;
    font-weight: bold;
    padding: 2px 4px;
    min-height: 20px;
    line-height: 1.3;
}

#trump-bar .trump-cards {
    display: inline-flex;
    gap: 2px;
    vertical-align: middle;
    margin-left: 4px;
}

#trump-bar .mini-card {
    display: inline-block;
    background: white;
    color: #2c3e50;
    border-radius: 3px;
    font-size: 10px;
    padding: 1px 4px;
    font-weight: bold;
}
#trump-bar .mini-card.red { color: #e74c3c; }

/* ============ 牌桌：四家出牌各在自己门前 ============ */
#round-zone {
    width: 100%;
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    grid-template-areas:
        "top top top"
        "left mid right"
        "self self self";
    gap: 3px;
    margin: 2px 0;
    flex-shrink: 1;   /* ★ 空间不够时可压缩（优先保消息/按钮） */
    min-height: 0;
    overflow: hidden;
}

#area-top { grid-area: top; }
#area-left { grid-area: left; }
#area-right { grid-area: right; }
#area-self { grid-area: self; }

#area-mid {
    grid-area: mid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 60px;
    min-width: 0;
    overflow: hidden;
}

.round-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 3px 5px;
    min-height: 36px;
}

.round-area.side-area {
    flex-direction: column;
    justify-content: center;
    padding: 4px 3px;
}

.round-area.current {
    background: rgba(241, 196, 15, 0.16);
    border-color: rgba(241, 196, 15, 0.6);
    box-shadow: 0 0 8px rgba(241, 196, 15, 0.35);
}

.round-area.winner {
    background: rgba(46, 204, 113, 0.22);
    border-color: rgba(46, 204, 113, 0.6);
}

.round-area .area-name {
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.72);
    font-size: 10px;
    font-weight: bold;
}

.round-area .area-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    align-items: center;
    justify-content: center;
}

.side-area .area-cards {
    flex-direction: column;
}

.round-area .area-cards .card {
    width: 30px;
    height: 42px;
    font-size: 9px;
    padding: 2px;
    border-radius: 4px;
    cursor: default;
}
.round-area .area-cards .card .value-center { font-size: 12px; }
.round-area .area-cards .card .suit-top,
.round-area .area-cards .card .suit-bottom { font-size: 9px; }

/* 底牌区 */
#bottom-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2px 4px;
    min-height: 30px;
    width: 100%;
}

#bottom-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    white-space: nowrap;
}

#bottom-cards {
    display: flex;
    flex-wrap: wrap;            /* ★ 允许换行，防止撑爆中间列（2026-09-11） */
    justify-content: center;
    gap: 2px;
    max-width: 100%;
}

#bottom-cards .card {
    width: 26px;
    height: 36px;
    font-size: 8px;
    padding: 1px;
    border-radius: 3px;
    cursor: default;
}
#bottom-cards .card .value-center { font-size: 10px; }
#bottom-cards .card-back {
    width: 26px;
    height: 36px;
    border-radius: 3px;
}

#message {
    color: white;
    font-size: 13px;
    font-weight: bold;
    text-align: center;
    padding: 5px 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    margin: 4px 0;
    min-height: 30px;
    width: 100%;
    line-height: 1.35;
    flex-shrink: 0;   /* ★ 永保可见 */
}

/* 按钮区 */
#controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;   /* ★ 永保可见（修复按钮被手牌区挡住，2026-09-11） */
}

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

#btn-play { background: #27ae60; color: white; }
#btn-confirm-bottom { background: #e67e22; color: white; }
#btn-sort { background: #3498db; color: white; }
.btn-gray { background: #95a5a6 !important; color: white !important; }

.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: 22px;
    border-radius: 12px;
    text-align: center;
    max-width: 92%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.modal-content h2 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 19px;
}
.modal-content p {
    color: #7f8c8d;
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.5;
}

.modal-btns {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
}

#declare-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-bottom: 6px;
    padding: 6px;
}
#declare-cards .card {
    width: 52px;
    height: 73px;
}
#declare-cards .card .value-center { font-size: 18px; }

/* 结算弹窗内容 */
#end-message {
    color: #34495e;
    font-size: 14px;
    line-height: 1.8;
    margin-bottom: 14px;
    text-align: left;
}
#end-message .hl {
    color: #e74c3c;
    font-weight: bold;
}
#end-message .win {
    color: #27ae60;
    font-weight: bold;
}

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

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

#hand-hint {
    text-align: center;
    font-size: 11px;
    color: #f1c40f;
    padding: 2px 0;
}
#hand-hint.hidden { display: none; }

/* 发牌等待提示（闪烁） */
.deal-badge {
    color: #f1c40f;
    font-size: 12px;
}

/* ============ 手机竖屏（默认）小尺寸 ============ */
@media (max-width: 380px) {
    .card {
        width: 42px;
        height: 60px;
        font-size: 10px;
        padding: 3px;
    }
    #hand-self .card { margin-left: -18px; }
    .card .value-center { font-size: 15px; }
    .card .suit-top,
    .card .suit-bottom { font-size: 11px; }
    #hand-self { min-height: 90px; }
    .round-area .area-cards .card { width: 25px; height: 35px; }
    #round-zone { grid-template-columns: 56px 1fr 56px; }
    .side-player { width: 52px; }
}

/* ============ 横屏手机 / 平板 ============ */
@media (min-width: 700px) and (orientation: landscape), (min-width: 900px) and (orientation: portrait) {
    .card {
        width: 58px;
        height: 82px;
        font-size: 14px;
    }
    #hand-self .card { margin-left: -20px; }
    #hand-self { min-height: 120px; }
    .card .value-center { font-size: 20px; }
    .card .suit-top,
    .card .suit-bottom { font-size: 15px; }
    .round-area .area-cards .card { width: 38px; height: 52px; }
    .round-area .area-cards .card .value-center { font-size: 14px; }
    #round-zone { grid-template-columns: 88px 1fr 88px; }
    #hand-top { max-height: 36px; }
    .card-back { width: 18px; height: 27px; }
    .side-player { width: 80px; }
    .player-info { font-size: 13px; padding: 6px 12px; }
    #message { font-size: 15px; }
    .btn { padding: 11px 24px; font-size: 14px; }
    #bottom-cards .card { width: 32px; height: 45px; }
    #declare-cards .card { width: 60px; height: 84px; }
}

/* ============ 电脑 / 大屏 ============ */
@media (min-width: 1100px) {
    #score-info {
        font-size: 14px;
        padding: 5px 20px;
        top: 8px;
    }
    .card {
        width: 72px;
        height: 100px;
        font-size: 16px;
        border-radius: 9px;
        padding: 6px;
    }
    #hand-self .card { margin-left: -32px; }
    #hand-self { min-height: 168px; padding: 18px 14px 22px; }
    #hand-self .card.selected { transform: translateY(-22px) !important; }
    .card .value-center { font-size: 26px; }
    .card .suit-top,
    .card .suit-bottom { font-size: 19px; }
    .round-area .area-cards .card {
        width: 46px;
        height: 64px;
        font-size: 12px;
        padding: 3px;
    }
    .round-area .area-cards .card .value-center { font-size: 18px; }
    .round-area .area-cards .card .suit-top,
    .round-area .area-cards .card .suit-bottom { font-size: 13px; }
    .round-area { min-height: 48px; }
    .round-area .area-name { font-size: 12px; }
    #round-zone { grid-template-columns: 130px 1fr 130px; }
    .last-label { font-size: 15px; }
    #message {
        font-size: 16px;
        padding: 10px 14px;
        min-height: 40px;
        margin: 8px 0;
    }
    #controls { gap: 14px; }
    .btn {
        padding: 13px 36px;
        font-size: 16px;
        border-radius: 22px;
    }
    .side-player { width: 120px; }
    .side-player .hand-cards { max-height: 140px; gap: 3px; }
    .card-back { width: 22px; height: 33px; border-radius: 5px; }
    #hand-top { max-height: 46px; min-height: 42px; padding: 6px 16px; }
    #opponents { padding-top: 32px; }
    #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: 14px;
        padding: 8px 14px;
        min-height: 38px;
    }
    .player-info .level { font-size: 12px; padding: 3px 10px; }
    .player-info .count { font-size: 12px; padding: 3px 10px; }
    .modal-content { padding: 30px 40px; }
    .modal-content h2 { font-size: 24px; }
    .modal-content p { font-size: 16px; }
    #declare-cards { gap: 6px; }
    #declare-cards .card { width: 68px; height: 95px; }
    #declare-cards .card .value-center { font-size: 24px; }
    #bottom-cards .card { width: 38px; height: 53px; }
    #bottom-cards .card .value-center { font-size: 13px; }
    #bottom-cards .card-back { width: 38px; height: 53px; }
    #trump-bar { font-size: 14px; min-height: 24px; }
    #end-message { font-size: 16px; }
}
