/* 牌的样式 */
.card {
    width: var(--card-width);
    height: var(--card-height);
    background: white;
    border-radius: 8px;
    border: 1px solid #999;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0; /* 图片模式下不需要padding */
    box-sizing: border-box;
    font-weight: bold;
    font-size: 18px;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
    overflow: hidden;
}
.card.selected { transform: translateY(-20px); border-color: gold; box-shadow: 0 0 10px gold; }
.card.red { color: #d32f2f; }
.card.black { color: #212121; }

/* 图片样式 */
.card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

/* 纯CSS绘制的后备样式 (当图片加载失败时显示) */
.card-text-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 5px;
    box-sizing: border-box;
    background: white;
    position: absolute;
    top: 0; left: 0;
    z-index: -1; /* 在图片下面 */
    border-radius: 6px; /* 匹配卡片圆角 */
}
.card-center { font-size: 36px; align-self: center; }
.card-corner { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.card-corner.bottom { transform: rotate(180deg); }

/* 信息面板 */
#info-panel {
    position: absolute;
    top: 10px;
    right: 10px; /* 改为右上角 */
    left: auto;
    bottom: auto;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-size: 14px;
    z-index: 100; 
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* 右对齐 */
}

.info-row {
    margin-bottom: 5px;
}

/* 状态栏按钮容器 */
.status-bar-buttons {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}

/* 小按钮样式 */
.small-btn {
    padding: 4px 8px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    border-radius: 4px;
    box-shadow: none;
}

.small-btn:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}

.small-btn:active {
    transform: translateY(1px);
}

/* 控制按钮 */
#controls {
    position: absolute;
    bottom: calc(var(--card-height) + 40px); /* 动态跟随手牌高度 */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row; /* 强制横向排列 */
    gap: 20px; /* 间距 */
    z-index: 100;
    flex-wrap: nowrap; /* 禁止换行 */
    justify-content: center;
    width: auto; /* 宽度自适应 */
    pointer-events: none; /* 容器不阻挡点击 */
}
#controls > * {
    pointer-events: auto; /* 按钮恢复点击 */
}

/* 游戏操作按钮通用样式 (出牌、不要、叉、准备、还贡) */
#btn-play, #btn-pass, #btn-cha, #btn-ready, #btn-return-tribute,
#btn-lobby-ready, #btn-lobby-stand, #btn-lobby-start, #btn-lobby-leave,
#btn-join-room, #btn-create-room {
    width: 120px; /* 统一宽度 */
    height: 44px; /* 统一高度 */
    padding: 0;
    font-size: 16px; /* 统一字体大小 */
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.6);
    border-radius: 22px; /* 圆角 */
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    transition: all 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* 防止被压缩 */
    margin: 5px;
}

#btn-play:active, #btn-pass:active, #btn-cha:active, #btn-ready:active, #btn-return-tribute:active,
#btn-lobby-ready:active, #btn-lobby-stand:active, #btn-lobby-start:active, #btn-lobby-leave:active,
#btn-join-room:active, #btn-create-room:active { 
    transform: translateY(2px); 
    box-shadow: 0 2px 3px rgba(0,0,0,0.3); 
}

/* 禁用状态：灰色、低饱和度 */
#btn-play:disabled, #btn-pass:disabled, #btn-cha:disabled, #btn-ready:disabled, #btn-return-tribute:disabled,
#btn-lobby-ready:disabled, #btn-lobby-stand:disabled, #btn-lobby-start:disabled, #btn-lobby-leave:disabled,
#btn-join-room:disabled, #btn-create-room:disabled { 
    background: #9e9e9e !important; 
    color: #ccc !important;
    border-color: #777 !important;
    box-shadow: none; 
    cursor: not-allowed; 
    transform: none;
    filter: grayscale(100%); /* 去色 */
    opacity: 0.7;
}

/* 按钮颜色区分 */
#btn-play { background: #4caf50; color: white; } /* 绿色 */
#btn-play:hover { background: #43a047; }

#btn-pass { background: #f44336; color: white; } /* 红色 */
#btn-pass:hover { background: #e53935; }

#btn-cha { background: #2196f3; color: white; } /* 蓝色 */
#btn-cha:hover { background: #1e88e5; }

#btn-ready { background: #ffc107; color: #333; } /* 黄色 */
#btn-ready:hover { background: #ffb300; }

#btn-return-tribute { background: #9c27b0; color: white; } /* 紫色 */
#btn-return-tribute:hover { background: #8e24aa; }

/* 大厅按钮颜色 */
#btn-lobby-ready { background: #ffc107; color: #333; }
#btn-lobby-ready:hover { background: #ffb300; }

#btn-lobby-stand { background: #ff9800; color: white; }
#btn-lobby-stand:hover { background: #f57c00; }

#btn-lobby-start { background: #4caf50; color: white; }
#btn-lobby-start:hover { background: #43a047; }

#btn-lobby-leave { background: #f44336; color: white; }
#btn-lobby-leave:hover { background: #d32f2f; }

#btn-join-room { background: #2196f3; color: white; }
#btn-join-room:hover { background: #1e88e5; }

#btn-create-room { background: #9c27b0; color: white; }
#btn-create-room:hover { background: #8e24aa; }

/* 记牌器 */
#card-counter {
    position: absolute;
    top: 10px;
    left: 10px; /* 改为左上角 */
    right: auto;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 5px; 
    border-radius: 5px;
    font-size: 12px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px; 
    text-align: center;
    pointer-events: none;
    z-index: 50;
}
.counter-item {
    display: flex;
    flex-direction: column;
}
.counter-rank {
    font-weight: bold;
    color: #ffc107;
}

/* 头像样式 */
.avatar-container {
    position: relative;
    width: 50px;
    height: 50px;
    margin-bottom: 0; /* 由group控制间距 */
    flex-shrink: 0; 
}

.avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #beb56f; /* 默认底色 */
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    /* 移除旧的绘制代码，改为文字显示 */
    background-image: none;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 20px;
    font-weight: bold;
    overflow: hidden;
}

/* 庄家高亮 */
.avatar-container.dealer .avatar {
    border: 3px solid gold;
    box-shadow: 0 0 10px gold;
}

.dealer-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background-color: gold;
    color: #d32f2f;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: bold;
    border: 1px solid #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
    z-index: 10;
}

/* 完成名次标记 */
.finished-badge {
    position: absolute;
    top: -5px;
    left: -5px;
    background-color: #f44336;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    z-index: 15;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 新增：玩家名字样式 */
.player-name {
    color: white;
    margin-top: 5px;
    font-size: 14px;
    text-shadow: 1px 1px 2px black;
    text-align: center;
    white-space: nowrap;
}

/* 新增：玩家信息组 (头像+名字) */
.player-info-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
    z-index: 20;
    position: relative; 
}

/* 移除旧的 status-bubble 样式，添加新的 status-text 样式 */
.status-text {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    white-space: nowrap;
    animation: popIn 0.2s ease-out;
    border: 1px solid #ddd;
}

/* 倒计时样式 (数码管风格) */
#game-timer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #000;
    color: #ff0000; /* 红色数码管 */
    font-family: 'DS-Digital', 'Courier New', Courier, monospace; /* 使用数码管字体 */
    font-size: 48px; /* 增大字体 */
    font-weight: normal; /* 数码管字体通常不需要粗体 */
    padding: 5px 0; /* 左右内边距设为0，由width和text-align控制居中 */
    width: 120px; /* 固定宽度，防止数字跳动 */
    border: 4px solid #333; /* 加厚边框 */
    border-radius: 8px;
    z-index: 5; 
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.3);
    pointer-events: none;
    letter-spacing: normal; /* 移除字间距，由span控制 */
    /* text-align: center;  Removed, using flex */
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box; /* 确保边框计算在宽度内 */
    
    /* Flex layout for fixed digit positions */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2px;
}

#game-timer span {
    display: inline-block;
    width: 34px; /* 固定每个数字的宽度，确保位置不跳动 */
    text-align: center;
}

/* 倒计时紧急状态动画：只闪烁边框 */
@keyframes timer-border-flash {
    0% { 
        border-color: #333; 
        box-shadow: 0 0 15px rgba(255, 0, 0, 0.3); 
    }
    50% { 
        border-color: #ff0000; 
        box-shadow: 0 0 30px rgba(255, 0, 0, 0.8); 
    }
    100% { 
        border-color: #333; 
        box-shadow: 0 0 15px rgba(255, 0, 0, 0.3); 
    }
}

.timer-warning {
    animation: timer-border-flash 0.5s infinite; /* 0.5秒闪烁一次 */
    /* 内容保持静态，不闪烁，颜色保持红色 */
    color: #ff0000 !important;
    text-shadow: none !important;
    opacity: 1 !important;
}

/* 版本页脚样式 */
#version-footer {
    position: absolute;
    bottom: 5px;
    right: 10px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    z-index: 50;
    pointer-events: auto;
}

.link-btn {
    background: none;
    border: none;
    color: #81d4fa;
    cursor: pointer;
    padding: 0;
    font-size: 12px;
    text-decoration: underline;
    box-shadow: none;
    font-weight: normal;
}

.link-btn:hover {
    color: #fff;
    background: none;
    box-shadow: none;
    transform: none;
}

.separator {
    margin: 0 5px;
    color: rgba(255, 255, 255, 0.4);
}
