:root {
    --table-green: #0f5d3c;
    --gold: #ffd700;
    --red: #e74c3c;
    --black: #2c3e50;
    --long-color: #3498db;
    --hu-color: #e74c3c;
                --primary-color: #FFFFFF;
             --primary-color1: #D4AF37;
            --primary-light: #E8C547;
            --primary-dark: #B8960C;
            --accent-color: #C7503E;
            --accent-light: #DD6B5A;
            --bg-body-start: #FDFBF7;
            --bg-body-end: #F5EFE0;
            --bg-card: rgba(255, 255, 255, 0.35);
            --bg-card-hover: rgba(255, 255, 255, 0.35);
            --bg-card-strong: rgba(255, 255, 255, 0.45);
            --text-primary: #2C2416;
            --text-secondary: #5C4F3A;
             --text-secondary1: #FFFFFF;
            --text-muted: #8A827E;
            --text-white: #FFFFFF;
            --text-black: #1A1A1A;
            --text-red: #C7503E;
            --border-glass: rgba(255, 255, 255, 0.5);
            --border-glass-strong: rgba(255, 255, 255, 0.7);
            --shadow-sm: 0 2px 8px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
            --shadow-md: 0 8px 24px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);
            --shadow-lg: 0 20px 60px rgba(0,0,0,0.12), 0 10px 24px rgba(0,0,0,0.1);
            --shadow-btn: 0 4px 14px rgba(212, 175, 55, 0.35), 0 2px 6px rgba(0,0,0,0.08);
            --shadow-btn-active: inset 0 2px 4px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.05);
            --radius-sm: 12px;
            --radius-md: 20px;
            --radius-lg: 28px;
            --transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

body { margin: 0; padding: 0; font-family: "Microsoft YaHei", sans-serif; overflow: hidden; background: #333; }
.hidden { display: none !important; }
.screen { width: 100vw; height: 100vh; }
  /* 全局基础重置 */
        * { box-sizing: border-box; }
        html, body { 
            height: 100%; 
            margin: 0; 
            padding: 0; 
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
            background: linear-gradient(160deg, var(--bg-body-start) 0%, var(--bg-body-end) 100%);
            color: var(--text-primary);
            overflow-x: hidden;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        
        /* 屏幕切换类 - 完全保留原有逻辑 */
        .screen { display: none; }
        .screen.active { display: block; }
        .hidden { display: none !important; }

        /* ================== 【核心修复】弹窗类 彻底解决跳变问题 ================== */
        .modal.hidden {
            display: flex !important;
            visibility: hidden !important;
            opacity: 0 !important;
            pointer-events: none !important;
        }
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 10001;
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
            transition: opacity 0.25s ease, visibility 0.25s ease;
        }
        .modal .modal-content {
            max-width: 460px !important;
            width: 90% !important;
            box-sizing: border-box;
            padding: 36px;
            border-radius: var(--radius-md);
            background: var(--bg-card-strong);
            backdrop-filter: blur(48px) saturate(220%);
            -webkit-backdrop-filter: blur(48px) saturate(220%);
            border: 1px solid var(--border-glass-strong);
            color: var(--text-black);
            box-shadow: var(--shadow-lg);
            transform-origin: center center;
            will-change: transform, opacity;
        }
        .modal:not(.hidden) .modal-content {
            animation: modalPopCenter 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }
        @keyframes modalPopCenter {
            from { opacity: 0; transform: scale(0.92); }
            to { opacity: 1; transform: scale(1); }
        }
        .modal .nickname-input {
            width: 100% !important;
            box-sizing: border-box;
            margin-bottom: 14px;
            border-radius: var(--radius-sm);
            border: 1px solid rgba(0,0,0,0.15);
            background: rgba(255,255,255,0.9);
            color: var(--text-black);
            font-weight: 600;
            padding: 14px 16px;
            transition: var(--transition);
            font-size: 15px;
        }
        .modal .nickname-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 6px rgba(212, 175, 55, 0.18);
            background: #ffffff;
            transform: translateY(-2px);
        }
        .modal .nickname-input::placeholder {
            color: var(--text-muted);
        }
        .modal .nickname-input[readonly] {
            background: #f0f0f0;
            cursor: not-allowed;
            opacity: 0.8;
            border-color: #ccc;
        }
        .modal h2 {
            color: var(--text-black);
            font-weight: 900;
            margin-bottom: 12px;
            font-size: 1.8rem;
        }
        .modal p {
            color: var(--text-secondary);
            font-weight: 500;
            line-height: 1.7;
            font-size: 15px;
        }

        /* ================== 【修复】用户下拉菜单无跳变 ================== */
        .user-menu {
            position: absolute;
            top: 100%;
            right: 0;
            padding-top: 20px;
            width: 260px;
            background: transparent;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-8px);
            transition: opacity 0.3s ease-out, transform 0.3s ease-out, visibility 0.3s;
            z-index: 10000;
            margin: 0 -10px;
            padding-left: 10px;
            padding-right: 10px;
            display: block !important;
            pointer-events: none;
        }
        .user-center:hover .user-menu {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
            pointer-events: auto;
        }
        .user-menu .menu-content {
            background: var(--bg-card-strong);
            backdrop-filter: blur(40px) saturate(200%);
            -webkit-backdrop-filter: blur(40px) saturate(200%);
            border: 1px solid var(--border-glass-strong);
            border-radius: var(--radius-md);
            box-shadow: var(--shadow-lg);
            padding: 20px;
        }
        .user-menu .user-stats-mini {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 14px;
            margin-bottom: 18px;
            padding-bottom: 18px;
            border-bottom: 1px solid rgba(0,0,0,0.08);
        }
        .user-menu .stat-mini {
            text-align: center;
            padding: 12px 8px;
            background: rgba(255,255,255,0.5);
            border-radius: var(--radius-sm);
            box-shadow: var(--shadow-sm);
        }
        .user-menu .stat-mini .val {
            font-size: 22px;
            font-weight: 900;
            color: var(--text-red);
        }
        .user-menu .stat-mini .label {
            font-size: 12px;
            color: var(--text-black);
            font-weight: 600;
            margin-top: 6px;
        }
        .user-menu .btn {
            width: 100%;
            margin: 8px 0;
            font-size: 14px;
            padding: 12px 0;
            border-radius: var(--radius-sm);
            font-weight: 700;
        }


        /* ================== 2. 大厅整体布局 滚动修复 ================== */
        .lobby-wrapper {
            width: 100%;
            height: 100vh;
            max-width: 1400px; /* 🔥 电脑端限制最大宽度 */
            margin: 0 auto;    /* 🔥 自动水平居中 */
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            padding: 36px 24px;
            overflow: hidden;
        }
        .lobby-header {
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 40px;
            flex-wrap: wrap;
            gap: 15px;
            position: relative;
            min-height: 60px;
            flex-shrink: 0;
        }
        .lobby-header h1 {
            margin: 0;
            line-height: 1.3;
            font-size: 2.80rem;
            font-weight: 900;
            background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 40%, var(--accent-color) 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            text-align: center;
            letter-spacing: 4px;
            text-shadow: 0 4px 12px rgba(212, 175, 55, 0.15);
        }
        .lobby-main {
            width: 100%;
            display: flex;
            gap: 32px;
            flex: 1;
            flex-wrap: wrap;
            min-height: 0;
            overflow: hidden;
        }

        /* ================== 3. 昵称样式 ================== */
        .user-center {
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
            z-index: 999;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            padding-bottom: 20px;
        }
        .user-nick {
            font-size: 1.1rem;
            font-weight: 700;
            color: var(--text-white);
            cursor: pointer;
            transition: var(--transition);
            background: linear-gradient(145deg, rgba(44, 36, 22, 0.85), rgba(60, 50, 30, 0.9));
            padding: 10px 22px;
            border-radius: var(--radius-lg);
            border: 1px solid rgba(255, 255, 255, 0.25);
            box-shadow: var(--shadow-md);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
        }
        .user-nick:hover {
            color: var(--primary-light);
            background: linear-gradient(145deg, rgba(60, 50, 30, 0.9), rgba(80, 65, 40, 0.95));
            transform: translateY(-2px);
            box-shadow: var(--shadow-lg);
            border-color: var(--primary-color);
        }

        /* ================== 4. 排行榜 ================== */
        .rank-container {
            background: linear-gradient(145deg, rgba(44, 36, 22, 0.85), rgba(60, 50, 30, 0.8));
            backdrop-filter: blur(36px) saturate(180%);
            -webkit-backdrop-filter: blur(36px) saturate(180%);
            border: 1px solid rgba(255,255,255,0.2);
            border-radius: var(--radius-md);
            overflow: hidden;
            box-shadow: var(--shadow-md);
            transition: var(--transition);
            flex-shrink: 0;
        }
        .rank-container:hover {
            box-shadow: var(--shadow-lg);
            transform: translateY(-4px);
            border-color: rgba(255,255,255,0.35);
        }
        .rank-toggle-btn {
            width: 100%;
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
            color: #ffffff;
            border: none;
            padding: 16px 0;
            font-size: 16px;
            font-weight: 800;
            cursor: pointer;
            display: none;
            transition: var(--transition);
            letter-spacing: 1px;
            box-shadow: var(--shadow-btn);
        }
        .rank-toggle-btn:hover {
            background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
            transform: translateY(-2px);
        }
        .rank-tabs {
            display: flex;
            background: rgba(255, 255, 255, 0.1);
            margin: 0;
            position: relative;
            padding: 8px;
            gap: 6px;
        }
        .rank-tab {
            flex: 1;
            text-align: center;
            padding: 12px 0;
            cursor: pointer;
            font-size: 13px;
            font-weight: 700;
            color: rgba(255,255,255,0.75);
            transition: var(--transition);
            position: relative;
            z-index: 1;
            border-radius: 12px;
        }
        .rank-tab.active {
            color: #ffffff;
            font-weight: 800;
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
            box-shadow: var(--shadow-btn);
        }
        .rank-tab:hover:not(.active) {
            color: #ffffff;
            background: rgba(255,255,255,0.15);
        }
        .rank-content {
            padding: 16px;
            max-height: 520px;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        .rank-item {
            display: flex;
            align-items: center;
            padding: 14px 12px;
            border-radius: var(--radius-sm);
            transition: var(--transition);
            margin-bottom: 6px;
            background: rgba(255,255,255,0.0);
        }
        .rank-item:hover {
            background: rgba(255, 255, 255, 0.08);
            transform: translateX(6px);
            box-shadow: var(--shadow-sm);
        }
        .rank-item .rank-num {
            width: 38px;
            text-align: center;
            font-weight: 900;
            font-size: 16px;
            color: var(--text-white);
            opacity: 0.85;
        }
        .rank-item .rank-num.top1 { 
            color: var(--primary-light); 
            font-size: 22px;
            font-weight: 900;
            text-shadow: 0 2px 8px rgba(212, 175, 55, 0.6);
            opacity: 1;
        }
        .rank-item .rank-num.top2 { color: #E0E0E0; font-weight: 900; opacity: 1; }
        .rank-item .rank-num.top3 { color: #D4AF37; font-weight: 900; opacity: 1; }
        .rank-item .rank-nickname {
            flex: 1;
            font-size: 15px;
            color: var(--text-white);
            font-weight: 600;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            margin: 0 12px;
        }
        .rank-item .rank-value {
            font-weight: 800;
            color: var(--text-white);
            font-size: 15px;
        }
        .rank-empty {
            text-align: center;
            color: var(--text-white);
            padding: 40px 0;
            font-size: 15px;
            font-weight: 600;
        }
        .rank-content::-webkit-scrollbar {
            width: 6px;
        }
        .rank-content::-webkit-scrollbar-thumb {
            background: rgba(255, 255, 255, 0.3);
            border-radius: 6px;
        }
        .rank-content::-webkit-scrollbar-track {
            background: rgba(0,0,0,0.1);
        }

        /* ================== 5. 房间列表容器 滚动修复 ================== */
        .lobby-container {
            flex: 1;
            min-width: 300px;
            background: var(--bg-card);
            backdrop-filter: blur(36px) saturate(180%);
            -webkit-backdrop-filter: blur(36px) saturate(180%);
            border: 1px solid var(--border-glass);
            border-radius: var(--radius-md);
            padding: 32px;
            box-shadow: var(--shadow-md);
            transition: var(--transition);
            max-height: 100%;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            touch-action: pan-y;
            transform: translateZ(0);
            min-height: 0;
        }
        .lobby-container:hover {
            box-shadow: var(--shadow-lg);
            border-color: var(--border-glass-strong);
        }
        
        .room-section-title {
            font-size: 1.1rem;
            font-weight: 800;
            color: var(--primary-dark);
            margin-bottom: 12px;
            margin-top: 20px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .room-section-title:first-child { margin-top: 0; }
        
        .room-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px;
            background: rgba(255, 255, 255, 0.5);
            border-radius: var(--radius-sm);
            margin-bottom: 10px;
            box-shadow: var(--shadow-sm);
            transition: var(--transition);
            border: 1px solid transparent;
        }
        .room-item:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
            border-color: var(--primary-color);
        }

        .lobby-container .empty {
            color: var(--text-secondary1);
            text-align: center;
            padding: 20px 0;
            font-weight: 500;
            font-size: 14px;
            background: rgba(255,255,255,0.2);
            border-radius: var(--radius-sm);
            margin: 10px 0;
        }

        /* ================== 7. 按钮通用样式 ================== */
        .btn {
            display: inline-block;
            padding: 14px 32px;
            font-size: 12px;
            font-weight: 800;
            text-align: center;
            border-radius: var(--radius-lg);
            border: none;
            cursor: pointer;
            transition: var(--transition);
            text-decoration: none;
            letter-spacing: 0.5px;
            position: relative;
            overflow: hidden;
        }
        .btn.primary {
            background: linear-gradient(145deg, var(--primary-light) 0%, var(--primary-color1) 50%, var(--primary-dark) 100%);
            color: #ffffff;
            box-shadow: var(--shadow-btn), 0 1px 0 rgba(255,255,255,0.4) inset;
            text-shadow: 0 1px 2px rgba(0,0,0,0.15);
        }
        .btn.primary:hover {
            transform: translateY(-3px) scale(1.02);
            box-shadow: 0 8px 24px rgba(212, 175, 55, 0.45), 0 1px 0 rgba(255,255,255,0.4) inset;
            background: linear-gradient(145deg, var(--primary-color) 0%, var(--primary-dark) 100%);
        }
        .btn.primary:active {
            transform: translateY(0) scale(0.98);
            box-shadow: var(--shadow-btn-active);
        }
        .btn.secondary {
            background: rgba(255, 255, 255, 0.7);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            color: var(--text-black);
            border: 1px solid var(--border-glass);
            box-shadow: var(--shadow-sm);
        }
        .btn.secondary:hover {
            background: rgba(255,255,255,0.9);
            color: var(--primary-dark);
            border-color: var(--primary-color);
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
        }
        .btn.secondary:active {
            transform: translateY(0);
            box-shadow: var(--shadow-btn-active);
        }
        .btn.red {
            background: linear-gradient(145deg, var(--accent-light) 0%, var(--accent-color) 50%, #9A3426 100%);
            color: #ffffff;
            box-shadow: 0 4px 14px rgba(199, 80, 62, 0.35), 0 1px 0 rgba(255,255,255,0.3) inset;
        }
        .btn.red:hover {
            transform: translateY(-3px) scale(1.02);
            box-shadow: 0 8px 24px rgba(199, 80, 62, 0.45), 0 1px 0 rgba(255,255,255,0.3) inset;
            background: linear-gradient(145deg, var(--accent-color) 0%, #9A3426 100%);
        }
        .btn.red:active {
            transform: translateY(0) scale(0.98);
            box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
        }
        .btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none !important;
        }

        /* ================== 8. 电脑/横屏适配 ================== */
        @media (min-width: 768px), (orientation: landscape) {
            .rank-container {
                width: 330px;
                flex-shrink: 0;
            }
            .rank-toggle-btn {
                display: none !important;
            }
            .rank-content {
                display: block !important;
                max-height: calc(100vh - 240px);
            }
        }

        /* ================== 9. 手机竖屏适配 ================== */
        @media (max-width: 767px) and (orientation: portrait) {
            .lobby-main {
                flex-direction: column;
                gap: 20px;
                flex-wrap: nowrap;
            }
            .rank-container {
                width: 100%;
            }
            .rank-toggle-btn {
                display: block;
            }
            .rank-content {
                max-height: 0;
                padding: 0;
                overflow: hidden;
                transition: max-height 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), padding 0.4s ease-out;
            }
            .rank-container.rank-open .rank-content {
                max-height: 400px;
                padding: 16px;
            }
            .lobby-header {
                flex-direction: column;
                justify-content: center;
                text-align: center;
                position: relative;
                min-height: auto;
                padding-bottom: 20px;
                margin-bottom: 20px;
            }
            .lobby-header h1 {
                font-size: 1.8rem;
                margin-bottom: 16px;
            }
            .user-center {
                position: relative;
                right: auto;
                top: auto;
                transform: none;
                margin: 0 auto;
                align-items: center;
                padding-bottom: 0;
            }
            .user-menu {
                right: 50%;
                transform: translateX(50%) translateY(-8px);
                padding-top: 10px;
            }
            .user-center:hover .user-menu {
                transform: translateX(50%) translateY(0);
            }
            .modal .modal-content {
                width: 95% !important;
                padding: 28px 20px;
                max-height: 85vh;
                overflow-y: auto;
                -webkit-overflow-scrolling: touch;
            }
            .modal h2 {
                font-size: 1.5rem;
                margin-bottom: 10px;
            }
            .lobby-wrapper {
                padding: 28px 12px;
            }
            .lobby-container {
                padding: 20px 16px;
                max-height: unset;
                flex: 1;
                min-height: 0;
            }
            .room-item {
                padding: 12px 10px;
            }
            /* 手机注册弹窗专属优化 */
            #registerModal .modal-content {
                max-height: 88vh;
                padding: 24px 16px;
            }
            #registerModal .nickname-input {
                margin-bottom: 12px;
                padding: 12px 14px;
                font-size: 14px;
            }
            #registerModal h2 {
                font-size: 1.4rem;
                text-align: center;
            }
            #registerModal hr {
                margin: 10px 0 !important;
            }
            #registerModal .btn {
                padding: 12px 0;
                font-size: 14px;
            }
        }

/* 结算弹窗基础样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.30);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999 !important;
}
.modal-content {
    background: white;
    padding: 40px 60px;
    border-radius: 20px;
    text-align: center;
    max-width: 90vw;
    box-shadow: 0 0 30px var(--gold);
    border: 3px solid var(--gold);
}
.modal-content h2 {
    margin: 0 0 20px 0;
    font-size: 28px;
    color: var(--black);
}
.modal-content p {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #555;
}
.modal-score {
    display: flex;
    justify-content: space-around;
    gap: 40px;
    margin: 20px 0 30px 0;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 10px;
}
.modal-score div {
    font-size: 18px;
    font-weight: bold;
}

/* 大厅 */
#lobby { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); display: flex; justify-content: center; align-items: center; color: white; }
.lobby-container { text-align: center; width: 100%; }
.room-list { background: rgba(255,255,255,0.1); border-radius: 10px; margin-top: 20px; padding: 10px; max-height: 400px; overflow-y: auto; }
.room-item { display: flex; justify-content: space-between; padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.1); align-items: center; }
.room-item:last-child { border: none; }

/* 按钮 */
.btn { padding: 10px 20px; border: none; border-radius: 20px; cursor: pointer; font-size: 12px; font-weight: bold; transition: 0.2s; }
.btn.primary { background: var(--gold); color: var(--black); }
.btn.primary:hover { background: #e6c200; }
.btn.secondary { background: #555; color: white; }
.btn.red { background: var(--red); color: white; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 游戏界面 */
#game { background: var(--table-green); display: flex; flex-direction: column; }

.top-bar { 
    height: 75px; background: rgba(0,0,0,0.5); display: flex; justify-content: space-between; align-items: center; padding: 0 20px; color: white;
}
.team-score { display: flex; align-items: center; gap: 10px; font-weight: bold; padding: 8px 1px; border-radius: 10px; border: 2px solid; }
.team-score.long { border-color: var(--long-color); }
.team-score.hu { border-color: var(--hu-color); }
.team-info { display: flex; flex-direction: column; }
.team-name { font-size: 11px; }
.team-detail { font-size: 10px; opacity: 0.9; }
.info-center { text-align: center; }
.suit-text { font-size: 15px; }
.divider { margin: 0 10px; opacity: 0.5; }

.table-container { flex: 1; position: relative; }
.player-area { position: absolute; display: flex; flex-direction: column; align-items: center; }
.avatar { background: rgba(0,0,0,0.5); color: white; padding: 5px 15px; border-radius: 15px; margin-top: 5px; font-size: 12px; position: relative; font-weight: bold;}

/* 底牌显示区【层级高于中央提示区】 */
.bottom-cards {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 8px;
    z-index: 60 !important;
    align-items: center;
}
/* 弃牌显示区【层级高于中央提示区】 */
.discarded-cards {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 8px;
    z-index: 60 !important;
    align-items: center;
}

/* 手机竖屏明牌容器样式 - 不透明背景+边框+圆角 */
.mobile-card-container {
    background: rgba(0, 0, 0, 0.9) !important;
    padding: 12px 15px !important;
    border-radius: 15px !important;
    border: 2px solid var(--gold) !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3) !important;
}

/* 准备标签 */
.ready-tag {
    position: absolute;
    top: -25px;
    background: var(--gold);
    color: var(--black);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
    opacity: 0;
}
.ready-tag.show { opacity: 1; }

/* 队伍徽章 */
.team-badge {
    width: 20px; height: 20px; border-radius: 50%; margin-bottom: 5px; opacity: 0; transition: 0.3s;
}
.team-badge.long { background: var(--long-color); opacity: 1; box-shadow: 0 0 10px var(--long-color); }
.team-badge.hu { background: var(--hu-color); opacity: 1; box-shadow: 0 0 10px var(--hu-color); }

/* 高亮当前回合玩家 */
.player-area.active .avatar { box-shadow: 0 0 15px var(--gold); border: 1px solid var(--gold); }

/* 四个方位 */
.top { top: 20px; left: 50%; transform: translateX(-50%); }
/* 电脑版手牌区域整体下移，离底部操作面板更近 */
.bottom { bottom: 60px; left: 50%; transform: translateX(-50%); flex-direction: column-reverse; }
.left { left: 20px; top: 50%; transform: translateY(-50%); }
.right { right: 20px; top: 50%; transform: translateY(-50%); }

/* 牌背 */
.cards-back { display: flex; }
.cards-back div { width: 50px; height: 70px; background: #2c3e50; border-radius: 5px; margin-left: -35px; border: 2px solid #34495e; box-shadow: 2px 2px 5px rgba(0,0,0,0.3); }
.cards-back div:first-child { margin-left: 0; }
.cards-back.vertical { flex-direction: column; }
.cards-back.vertical div { margin-left: 0; margin-top: -50px; height: 50px; width: 35px; }
.cards-back.vertical div:first-child { margin-top: 0; }

/* 单张牌样式 */
.card {
    width: 80px;
    height: 100px;
    background: white;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 6px;
    box-sizing: border-box;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: 0.1s;
}
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card.joker { color: #333; background: linear-gradient(45deg, #ffecd2 0%, #fcb69f 100%); }

.card-value { font-size: 18px; font-weight: bold; line-height: 1.2; }
.card-suit-center { font-size: 30px; text-align: center; }

/* 我的手牌区域 */
.my-hand { display: flex; justify-content: center; height: 140px; align-items: flex-end; }
.my-hand .card { margin-left: -45px; }
.my-hand .card:first-child { margin-left: 0; }
.my-hand .card:hover { transform: translateY(-25px); z-index: 10; }
.my-hand .card.selected { transform: translateY(-35px); border: 3px solid var(--gold); z-index: 11; }

/* 出牌区【同步修改，和手牌保持固定间距】 */
.played-card { position: absolute; width: 80px; height: 115px; transition: 0.3s; z-index: 100;}
.top .played-card { top: 80px; }
/* 底部出牌区位置，和手牌保持相对位置不变 */
.bottom .played-card { bottom: 100px; z-index: 100;}
.left .played-card { left: 80px; }
.right .played-card { right: 80px; }

/* 赢家特效 */
.played-card.winner { transform: scale(1.1); z-index: 50; box-shadow: 0 0 20px var(--gold); }

/* 中央提示区【层级低于底牌/弃牌，字体大小优化】 */
.center-stage {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    text-align: center;
    font-size: 10px !important;
    font-weight: 800 !important;
    background: rgba(0,0,0,0.7) !important;
    padding: 13px 30px !important;
    border-radius: 20px !important;
    border: 3px solid var(--gold) !important;
    text-shadow: 2px 2px 4px black !important;
    z-index: 0 !important;
}

/* 操作面板 */
.action-panel { height: 100px; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; gap: 20px; }

/* 叫分按钮 */
.jiao-btn {
    padding: 15px 30px !important;
    font-size: 22px !important;
    border-radius: 12px !important;
    margin: 0 4px !important;
    border: 3px solid transparent !important;
    font-weight: bold !important;
    cursor: pointer !important;
    background: white !important;
    color: #2c3e50 !important;
    transition: 0.2s !important;
}
.jiao-btn:hover {
    transform: scale(1.1) !important;
    border-color: var(--gold) !important;
    box-shadow: 0 0 15px var(--gold) !important;
}
.jiao-btn.red {
    background: var(--red) !important;
    color: white !important;
}

/* 定主花色选框 */
.suit-select-btn {
    width: 70px !important;
    height: 70px !important;
    font-size: 36px !important;
    border-radius: 12px !important;
    border: 4px solid #555 !important;
    background: white !important;
    cursor: pointer !important;
    font-weight: bold !important;
    transition: 0.2s !important;
    margin: 0 8px !important;
}
.suit-select-btn:hover:not(:disabled) {
    transform: scale(1.15) !important;
    border-color: var(--gold) !important;
    box-shadow: 0 0 20px var(--gold) !important;
}
.suit-select-btn:disabled {
    opacity: 0.3 !important;
    cursor: not-allowed !important;
}

/* 手牌选中状态 */
.my-hand .card.selected {
    transform: translateY(-50px) !important;
    border: 4px solid var(--gold) !important;
    box-shadow: 0 0 25px var(--gold) !important;
}

/* =========================================================
   全自动最终版 | 竖屏优化
========================================================= */
/* 竖屏：保留我们调好的完美效果，不受电脑版修改影响 */
@media only screen and (max-width: 768px) and (orientation: portrait) {
  html,body{touch-action: manipulation; -webkit-text-size-adjust: 100%;}
  .screen{width:100vw; height:100dvh; overflow: hidden;}

  /* 竖屏弹窗适配 */
  .modal-content {
      padding: 30px 20px !important;
      max-width: 85vw !important;
  }
  .modal-content h2 {
      font-size: 22px !important;
  }
  .modal-content p {
      font-size: 16px !important;
  }
  .modal-score {
      flex-direction: column;
      gap: 10px !important;
  }

  /* 中央提示区竖屏缩小 */
  .center-stage {
      font-size: 12px !important;
      padding: 10px 20px !important;
      border-radius: 15px !important;
      border-width: 2px !important;
  }

  /* 操作面板调整为wrap，支持多行显示 */
  .action-panel {
    position: relative !important;
    z-index: 99 !important;
    margin: 0 auto 8px !important;
    padding: 6px 2px !important;
    border-radius: 10px !important;
    background: rgba(0,0,0,0.7) !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 8px !important;
  }

  /* 操作面板内元素全宽，方便换行 */
  .action-panel > div, .action-panel > span {
      width: 100% !important;
      text-align: center !important;
      margin: 4px 0 !important;
  }

  .player-area.bottom {
    bottom: 0 !important;
    flex-direction: column-reverse !important;
    margin: 0 !important;
    gap: 0 !important;
  }

  .my-hand {
    width: 100vw !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    padding: 0 12px 8px !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    box-sizing: border-box !important;
  }
  .my-hand::-webkit-scrollbar {display: none !important;}

  .my-hand .card {
    flex-shrink: 0 !important;
    margin-left: -20px !important;
  }
  .my-hand .card:first-child { margin-left: 0 !important; }

  .jiao-btn {
    transform: scale(0.7) !important;
    margin: 0 2px !important;
    padding: 0 !important;
  }

  .suit-select-btn {
    transform: scale(0.8) !important;
    margin: 0 4px !important;
  }

  .my-hand .card{width: 54px !important; height: 95px !important;}
  .action-panel{min-height: 50px;}

  /* 竖屏下底牌和弃牌保持水平排列，优化尺寸 */
  .bottom-cards, .discarded-cards {
      flex-direction: row;
      gap: 4px;
      padding: 8px !important;
      width: max-content !important;
  }
  .bottom-cards .card, .discarded-cards .card {
      width: 40px !important;
      height: 60px !important;
  }
  .bottom-cards .card-value, .discarded-cards .card-value {
      font-size: 10px !important;
  }
  .bottom-cards .card-suit-center, .discarded-cards .card-suit-center {
      font-size: 20px !important;
  }

  /* 手机竖屏明牌容器应用不透明样式 */
  .bottom-cards.mobile-card-container, .discarded-cards.mobile-card-container {
      max-width: 90vw !important;
      overflow-x: auto !important;
      -webkit-overflow-scrolling: touch !important;
      scrollbar-width: none !important;
      padding: 10px 15px !important;
  }
  .bottom-cards.mobile-card-container::-webkit-scrollbar, .discarded-cards.mobile-card-container::-webkit-scrollbar {
      display: none !important;
  }
}

/* =========================================================
   【竖屏版改造】手机横屏专属样式
   完全复用竖屏版布局逻辑，仅适配横屏宽高比，不改动原有竖屏/电脑版样式
========================================================= */
@media only screen and (max-width: 950px) and (orientation: landscape) {
    /* 1. 全局容器：关闭电脑版缩放，复用竖屏版全屏逻辑 */
    .screen {
        transform: none !important;
        transform-origin: unset !important;
        width: 100vw !important;
        height: 100vh !important;
        min-width: unset !important;
        min-height: unset !important;
        position: relative !important;
        overflow: hidden !important;
    }

    /* 2. 顶部信息栏：复用竖屏版结构，压缩高度适配横屏 */
    .top-bar {
        height: 42px !important;
        padding: 0 12px !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 999 !important;
    }
    .team-name {
        font-size: 13px !important;
    }
    .team-detail {
        font-size: 9px !important;
    }
    .main-suit-display .suit-text {
        font-size: 13px !important;
    }
    .main-suit-display .suit-icon {
        font-size: 18px !important;
    }

    /* 3. 玩家区域：完全复用竖屏版定位逻辑，适配横屏位置 */
    .player-area {
        position: absolute !important;
        z-index: 90 !important;
    }
    /* 我的区域（底部）：竖屏版逻辑，紧贴底部操作区上方 */
    .player-area.bottom {
        bottom: 52px !important; /* 和底部操作区高度完全对应，紧贴无间隙 */
        left: 0 !important;
        right: 0 !important;
        top: unset !important;
        transform: none !important;
        display: flex !important;
        flex-direction: column-reverse !important;
        align-items: center !important;
        gap: 4px !important;
    }
    /* 对家区域（顶部）：竖屏版逻辑，顶部信息栏下方 */
    .player-area.top {
        top: 47px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: unset !important;
        transform: none !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 4px !important;
    }
    /* 左侧玩家：竖屏版逻辑，左部垂直居中 */
    .player-area.left {
        left: 8px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        right: unset !important;
        bottom: unset !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 4px !important;
    }
    /* 右侧玩家：竖屏版逻辑，右部垂直居中 */
    .player-area.right {
        right: 8px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        left: unset !important;
        bottom: unset !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 4px !important;
    }

    /* 4. 玩家头像/准备标记：完全复用竖屏版样式，压缩尺寸 */
    .avatar {
        font-size: 11px !important;
        padding: 3px 8px !important;
        border-radius: 8px !important;
        position: relative !important;
    }
    .ready-tag {
        font-size: 9px !important;
        padding: 1px 4px !important;
        top: -16px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
    .team-badge {
        width: 14px !important;
        height: 14px !important;
        font-size: 9px !important;
    }

    /* 5. 对手手牌：复用竖屏版背面样式，压缩尺寸 */
    .opponent-hand {
        display: flex !important;
        gap: 0 !important;
        justify-content: center !important;
    }
    .opponent-hand .card-back {
        width: 36px !important;
        height: 54px !important;
        margin-left: -14px !important;
        border-radius: 6px !important;
    }
    .opponent-hand .card-back:first-child {
        margin-left: 0 !important;
    }
    .opponent-hand .card-back::before {
        font-size: 16px !important;
    }

 /* 6. 我的手牌区：伪元素居中 + 18张牌完整滚动（仅横屏修复） */
.my-hand {
    position: fixed !important;
    bottom: 52px !important;
    left: 0 !important;
    right: 0 !important;
    height: 100px !important;
    padding: 0 10px 4px !important;
    display: flex !important;
    justify-content: flex-start !important; /* 改回靠左，靠伪元素实现居中 */
    align-items: flex-end !important;
    gap: 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    z-index: 95 !important;
}

/* 🔥 核心：左右加伪元素，把牌挤到中间，视觉完全居中，又不影响滚动 */
.my-hand::before,
.my-hand::after {
    content: '' !important;
    flex: 1 !important; /* 左右各占一半空白 */
    flex-shrink: 0 !important; /* 禁止压缩空白 */
    min-width: 10px !important; /* 最小留白 */
}
    .my-hand::-webkit-scrollbar {
        display: none !important;
    }
    /* 手牌样式：复用竖屏版重叠逻辑，适配横屏高度 */
    .my-hand .card {
        width: 58px !important;
        height: 92px !important;
        border-radius: 8px !important;
        padding: 3px !important;
        margin-left: -28px !important;
        flex-shrink: 0 !important;
        position: relative !important;
        transition: transform 0.1s ease !important;
    }
    .my-hand .card:first-child {
        margin-left: 0 !important;
    }
    /* 手牌选中/hover效果：复用竖屏版逻辑，适配横屏 */
    .my-hand .card:hover {
        transform: translateY(-16px) !important;
        z-index: 100 !important;
    }
    .my-hand .card.selected {
        transform: translateY(-22px) !important;
        border: 2px solid var(--gold) !important;
        box-shadow: 0 0 10px var(--gold) !important;
        z-index: 101 !important;
    }
    /* 牌面文字：压缩尺寸适配手牌 */
    .card-value {
        font-size: 15px !important;
        font-weight: bold !important;
        line-height: 1 !important;
    }
    .card-suit-center {
        font-size: 25px !important;
        text-align: center !important;
    }

    /* 7. 底部操作区：复用竖屏版贴底逻辑，压缩高度变窄，完全贴底 */
    .action-panel {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 52px !important; /* 极致压缩，不占空间 */
        background: rgba(0,0,0,0.85) !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 0 10px !important;
        z-index: 999 !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.6) !important;
    }
    /* 操作按钮：复用竖屏版样式，压缩尺寸适配窄操作区 */
    .btn {
        padding: 6px 16px !important;
        font-size: 12px !important;
        border-radius: 10px !important;
        font-weight: bold !important;
    }
    .jiao-btn {
        padding: 7px 16px !important;
        font-size: 15px !important;
        border-radius: 10px !important;
        margin: 0 2px !important;
    }
    .suit-select-btn {
        width: 45px !important;
        height: 45px !important;
        font-size: 24px !important;
        margin: 0 4px !important;
    }

  /* 8. 生死局明牌/弃牌 —— 纯CSS自动判断，无需JS
   规则：有牌 → 显示黑底金边；空容器 → 彻底隐藏无背景
*/
.bottom-cards {
    top: 30% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 150 !important;
    /* 默认显示容器样式（有牌时生效） */
    background: rgba(0, 0, 0, 0.9) !important;
    padding: 10px 15px !important;
    border-radius: 15px !important;
    border: 2px solid var(--gold) !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3) !important;
}
.discarded-cards {
    top: 45% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 150 !important;
    /* 默认显示容器样式（有牌时生效） */
    background: rgba(0, 0, 0, 0.9) !important;
    padding: 10px 15px !important;
    border-radius: 15px !important;
    border: 2px solid var(--gold) !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3) !important;
}

/* 🔥 核心修复：空容器（无牌）→ 彻底隐藏背景/边框/内边距 */
.bottom-cards:empty,
.discarded-cards:empty {
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
}

/* 牌面尺寸样式不变 */
.bottom-cards .card, 
.discarded-cards .card {
    width: 42px !important;
    height: 63px !important;
    border-radius: 6px !important;
    padding: 2px !important;
    background: #ffffff !important;
    opacity: 1 !important;
}
.bottom-cards .card-value, 
.discarded-cards .card-value {
    font-size: 10px !important;
    font-weight: bold !important;
}
.bottom-cards .card-suit-center, 
.discarded-cards .card-suit-center {
    font-size: 16px !important;
}
    /* 9. 本轮出牌区：复用竖屏版九宫格布局，适配横屏居中 */
    .turn-cards {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        grid-template-rows: repeat(3, 1fr) !important;
        gap: 6px !important;
        width: 260px !important;
        height: 160px !important;
        z-index: 80 !important;
    }
    .turn-card-slot {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    .turn-card-slot.top { grid-column: 2 !important; grid-row: 1 !important; }
    .turn-card-slot.left { grid-column: 1 !important; grid-row: 2 !important; }
    .turn-card-slot.right { grid-column: 3 !important; grid-row: 2 !important; }
    .turn-card-slot.bottom { grid-column: 2 !important; grid-row: 3 !important; }
    .turn-card-slot .card {
        width: 45px !important;
        height: 68px !important;
        border-radius: 6px !important;
        padding: 2px !important;
    }
    .turn-card-slot .card-value {
        font-size: 11px !important;
    }
    .turn-card-slot .card-suit-center {
        font-size: 18px !important;
    }

    /* 10. 中央提示区：复用竖屏版样式，压缩尺寸不遮挡 */
    .center-stage {
        font-size: 12px !important;
        padding: 6px 20px !important;
        border-radius: 10px !important;
        border-width: 2px !important;
        z-index: 9900 !important;
    }
}
/* 修复电脑版 玩家自己（下方）队伍徽章+准备标签过高、换行问题 */
.player-area.bottom .team-badge {
  margin-bottom: 2px !important;
}
.player-area.bottom .ready-tag {
  top: -10px !important; /* 降低高度，不再飘太高 */
  white-space: nowrap !important; /* 强制不换行，解决两行问题 */
  width: auto !important;
  min-width: unset !important;
}
.player-area.bottom .avatar {
  margin-top: 8px !important; /* 微调头像间距，更协调 */
}
/* 电脑版 玩家自己出牌区下移，贴近手牌 */
@media not screen and (max-width: 768px) {
  .bottom .played-card {
    bottom: 120px !important;
    z-index: 9999 !important;
  }
}

/* ==================== 新增：昵称输入专属样式 ==================== */
.nickname-input {
    width: 100%;
    padding: 12px 20px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: 10px;
    box-sizing: border-box;
    margin: 15px 0;
    outline: none;
    transition: 0.2s;
}

.nickname-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.nickname-hint {
    font-size: 14px;
    color: #888;
    margin-bottom: 10px;
/* 原有样式保持不变，在最开头或最后添加： */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideDown 0.3s ease-out;
}
.toast.warning { border-left: 4px solid #f39c12; }
.toast.success { border-left: 4px solid #2ecc71; }
.toast.error { border-left: 4px solid #e74c3c; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
