:root {
    --bg: #1a5c2a;
    --table: #1e6b32;
    --gold: #d4a843;
    --card-face: #fdfdfd;     /* 麻将正面亮白 */
    --card-back: #27ae60;     /* 麻将背面绿色 */
    --card-side: #219653;     /* 麻将侧边暗绿色（制造立体感） */
    --joker-glow: #ff6b6b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: #0d3b1a;
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; user-select: none; overflow: hidden;
}

.game-container {
    width: 100vw; height: 100vh; max-width: 1300px; max-height: 920px;
    background: var(--table); border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    position: relative; display: flex; flex-direction: column;
    border: 6px solid #3d2b1f; overflow: hidden;
}
@media (max-width: 768px) { .game-container { border-radius: 0; border: 2px solid #3d2b1f; } }

.game-container::before {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, rgba(255,255,255,0.03) 0%, transparent 70%),
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.02) 2px, rgba(0,0,0,0.02) 4px);
    pointer-events: none; border-radius: 18px; z-index: 0;
}

/* 顶部状态栏 & 计分板 */
.top-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 20px; background: rgba(0,0,0,0.3); border-bottom: 2px solid rgba(255,255,255,0.1); z-index: 2; flex-shrink: 0; }
.top-bar .title { color: var(--gold); font-size: 1.1em; font-weight: bold; letter-spacing: 2px; }
.top-bar .info { color: #ddd; font-size: 0.8em; }
.top-bar .remaining { color: #ffd700; font-weight: bold; font-size: 0.85em; background: rgba(0,0,0,0.4); padding: 4px 14px; border-radius: 20px; }
.btn-restart { background: #f0e6d3; color: #333; border: 2px solid #c9a96e; padding: 6px 16px; border-radius: 20px; cursor: pointer; font-weight: bold; transition: all 0.2s; font-size: 0.85em; }
.btn-restart:hover { background: #fff; border-color: #e8c97a; }

.scoreboard { display: flex; justify-content: center; gap: 16px; padding: 6px 20px; background: rgba(0,0,0,0.2); border-bottom: 1px solid rgba(255,255,255,0.08); z-index: 2; flex-shrink: 0; flex-wrap: wrap; }
.score-item { display: flex; align-items: center; gap: 6px; font-size: 0.8em; }
.score-name { color: #ccc; font-size: 0.85em; }
.score-name.you { color: #ffd700; font-weight: bold; }
.score-value { color: #fff; font-weight: bold; background: rgba(0,0,0,0.3); padding: 2px 10px; border-radius: 10px; min-width: 50px; text-align: center; }
.score-pending { color: #8f8; font-size: 0.75em; }

/* 游戏区域布局 */
.main-area { flex: 1; display: flex; flex-direction: column; position: relative; z-index: 1; min-height: 0; }
.ai-area-top { display: flex; justify-content: center; align-items: flex-end; padding: 4px 10px; flex-shrink: 0; min-height: 65px; }
.ai-top-cards { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; }
.middle-row { display: flex; flex: 1; min-height: 0; align-items: center; justify-content: space-between; padding: 0 10px; }
.ai-area-left, .ai-area-right { width: 95px; display: flex; flex-direction: column; justify-content: center; align-items: center; flex-shrink: 0; }
.ai-left-cards, .ai-right-cards { display: flex; flex-direction: column; gap: 1px; align-items: center; }
.ai-side-row { display: flex; flex-direction: row; gap: 4px; align-items: center; }
.player-label-sm { color:#ffd700; font-size:0.7em; margin-bottom:3px; }

/* 牌河 */
.river-area { flex: 1; max-width: 600px; display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: center; gap: 4px; padding: 12px; overflow-y: auto; background: rgba(0,0,0,0.18); border-radius: 12px; margin: 0 10px; min-height: 100px; max-height: 240px; align-self: center; box-shadow: inset 0 2px 8px rgba(0,0,0,0.3); }
@media (max-width: 768px) { .river-area { max-height: 160px; padding: 6px; } }

/* 玩家区域 */
.player-area { display: flex; flex-direction: column; align-items: center; padding: 8px 10px 12px; flex-shrink: 0; background: rgba(0,0,0,0.25); border-top: 2px solid rgba(255,255,255,0.1); min-height: 130px; }
.player-label { color: #ffd700; font-weight: bold; letter-spacing: 2px; font-size: 0.9em; margin-bottom: 2px; }
.player-hand { display: flex; gap: 4px; flex-wrap: nowrap; justify-content: center; align-items: flex-end; width: 100%; max-width: 900px; padding: 0 4px; }

.meld-display { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin-bottom: 4px; min-height: 22px; }
.meld-group { display: flex; gap: 1px; background: rgba(255,255,255,0.08); border-radius: 6px; padding: 3px 5px; border: 1px dashed rgba(255,255,255,0.25); align-items: center; }
.meld-display-side { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.meld-group-side { display: flex; flex-direction: column; align-items: center; background: rgba(255,255,255,0.08); border-radius: 3px; padding: 1px 2px; border: 1px dashed rgba(255,255,255,0.2); }
.meld-group-side .meld-label { font-size: 0.4em; color: #ffd700; line-height: 1.2; }
.meld-group-side .meld-cards-row { display: flex; gap: 1px; }

/* ==============================================================
   🌟 极致彩色高清 SVG 渲染方案 (配合 3D 边框基座)
============================================================== */

/* 牌面图案通用容器 */
.card-face {
    width: 100%; height: 100%;
    background-size: 75% 85%;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 3px;
}

.card { 
    width: 48px; height: 68px;
    background: var(--card-face);
    border-top: 1px solid #e0e0e0; border-left: 1px solid #e0e0e0;
    border-bottom: 6px solid var(--card-back);
    border-right: 3px solid var(--card-side);
    border-radius: 5px; cursor: pointer; 
    display: flex; align-items: center; justify-content: center; 
    transition: all 0.15s ease; 
    box-shadow: 2px 3px 5px rgba(0,0,0,0.3);
    flex-shrink: 1; position: relative; max-width: 50px;
}

/* 白板百搭专属高亮特效 */
.card.joker-card { 
    background: linear-gradient(135deg, #fffef9, #ffe0e0); 
    border-bottom-color: #ff4757; border-right-color: #ff6b81; 
    box-shadow: 0 0 12px rgba(255,107,107,0.5); 
}
.card.joker-card .joker-badge { 
    position: absolute; top: -8px; right: -8px; 
    background: linear-gradient(to bottom, #ff6b6b, #ee5253); 
    color: #fff; font-size: 0.7em; font-weight: bold; padding: 2px 5px; 
    border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.4); z-index: 2;
}

.card:hover { transform: translateY(-8px); box-shadow: 2px 10px 15px rgba(0,0,0,0.4); z-index: 5; }
.card.selected { transform: translateY(-14px); border-bottom-color: #ff6b6b !important; box-shadow: 0 10px 24px rgba(255,107,107,0.5); z-index: 6; animation: pulse 0.8s infinite; }
@keyframes pulse { 0%,100%{box-shadow:0 10px 24px rgba(255,107,107,0.5);} 50%{box-shadow:0 14px 32px rgba(255,107,107,0.75);} }

/* 各种小尺寸牌的 3D 样式与贴图适配 */
.river-card { width: 32px; height: 46px; background: var(--card-face); border-bottom: 4px solid var(--card-back); border-right: 2px solid var(--card-side); border-radius: 4px; border-top: 1px solid #ccc; border-left: 1px solid #ccc; display: flex; align-items: center; justify-content: center; box-shadow: 1px 2px 3px rgba(0,0,0,0.2); }
.mini-card { width: 28px; height: 40px; background: var(--card-face); border-bottom: 4px solid var(--card-back); border-right: 2px solid var(--card-side); border-radius: 3px; display: flex; align-items: center; justify-content: center; box-shadow: 1px 1px 3px rgba(0,0,0,0.3); }
.mini-card-sm { width: 20px; height: 28px; background: var(--card-face); border-bottom: 3px solid var(--card-back); border-right: 1px solid var(--card-side); border-radius: 2px; display: flex; align-items: center; justify-content: center; }
.card-back { width: 34px; height: 48px; background: linear-gradient(135deg, #27ae60, #219653); border: 1px solid #1e8449; border-radius: 4px; box-shadow: inset 0 0 10px rgba(0,0,0,0.1), 1px 2px 4px rgba(0,0,0,0.3); }
.card-back-sm { width: 26px; height: 36px; }
.card-back-xs { width: 20px; height: 28px; }

@media (max-width: 768px) {
    .card { width: 7.2vw; height: 10vw; border-bottom-width: 3px; border-right-width: 2px; }
    .river-card { width: 6vw; height: 8.5vw; }
    .card-back { width: 5.5vw; height: 7.5vw; }
    .card-back-sm { width: 4.5vw; height: 6vw; }
    .card-back-xs { width: 3.5vw; height: 5vw; }
    .mini-card { width: 5.5vw; height: 8vw; }
    .card.joker-card .joker-badge { font-size: 0.55em; top:-5px; right:-5px; padding: 1px 4px;}
}

/* 操作按钮 & 弹窗 */
.action-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 4px 0; min-height: 30px; }
.btn { padding: 6px 16px; border-radius: 22px; border: 2px solid transparent; cursor: pointer; font-weight: bold; font-size: 0.85em; transition: all 0.2s; }
.btn-action { background: #fff; color: #333; border-color: #c9a96e; }
.btn-selfdraw { background: #ff6b6b; color: #fff; border-color: #e55a5a; animation: btnGlow 1.2s infinite; }
@keyframes btnGlow { 0%,100%{box-shadow:0 0 8px rgba(255,107,107,0.5);} 50%{box-shadow:0 0 22px rgba(255,107,107,0.9);} }
.btn-pass { background: #888; color: #fff; border-color: #666; }

.toast { position: fixed; top: 15px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.88); color: #ffd700; padding: 8px 24px; border-radius: 30px; font-weight: bold; z-index: 100; font-size: 0.9em; pointer-events: none; animation: toastIn 0.3s ease-out, toastOut 0.3s 1.5s ease-in forwards; }
@keyframes toastIn { from{opacity:0;transform:translateX(-50%) translateY(-20px);} to{opacity:1;transform:translateX(-50%) translateY(0);} }
@keyframes toastOut { from{opacity:1;} to{opacity:0;transform:translateX(-50%) translateY(-15px);} }

.win-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; justify-content: center; align-items: center; z-index: 200; overflow-y: auto; padding: 10px; }
.win-panel { background: linear-gradient(145deg, #1a0d05 0%, #2c1810 50%, #3d2b1f 100%); border: 3px solid #d4a843; border-radius: 20px; padding: 20px; max-width: 680px; width: 100%; text-align: center; box-shadow: 0 20px 80px rgba(0,0,0,0.9); animation: winPanelIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes winPanelIn { from { opacity:0; transform:scale(0.85) translateY(20px); } to { opacity:1; transform:scale(1) translateY(0); } }
.win-title { color: #ffd700; font-size: 1.4em; font-weight: bold; margin-bottom: 4px; text-shadow: 0 2px 8px rgba(0,0,0,0.6); }
.win-subtitle { color: #bbb; font-size: 0.8em; margin-bottom: 12px; }
.win-section-label { color: rgba(255,215,0,0.6); font-size: 0.65em; letter-spacing: 2px; margin: 8px 0 4px; }
.win-melds { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 4px; }
.win-meld-group { display: flex; gap: 1px; align-items: center; background: rgba(255,255,255,0.07); border-radius: 6px; padding: 4px 6px; border: 1px solid rgba(255,255,255,0.12); }
.win-meld-label { font-size: 0.5em; color: #ffd700; margin-right: 3px; }

/* 结算界面的卡牌样式 */
.win-hand { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; margin: 6px 0; }
.win-card { width: 36px; height: 50px; background: var(--card-face); border-bottom: 4px solid var(--card-back); border-right: 2px solid var(--card-side); border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.win-mini { width: 24px; height: 34px; background: var(--card-face); border-bottom: 3px solid var(--card-back); border-right: 2px solid var(--card-side); border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.win-card.win-joker { border-bottom-color: #ff4757; border-right-color: #ff6b81; box-shadow: 0 0 8px rgba(255,107,107,0.4); background: linear-gradient(135deg, #fffef9, #ffe0e0); }

.win-score-section { margin: 8px 0; padding: 10px; background: rgba(0,0,0,0.3); border-radius: 10px; border: 1px solid rgba(255,215,0,0.15); }
.win-peek-tiles { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.win-peek-tile { width: 30px; height: 42px; border-bottom: 3px solid #666; border-right: 2px solid #555; background: #ddd; border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.win-peek-tile.is-flip { border-bottom-color: #d4a843; border-right-color: #b8860b; background: #fff8e1; box-shadow: 0 0 8px rgba(255,215,0,0.5); }
.win-score-detail { font-size: 0.8em; color: #ddd; line-height: 1.6; text-align: left; padding: 0 5px; }
.win-score-detail .label { color: #aaa; }
.win-score-detail .val { color: #ffd700; font-weight: bold; }
.win-score-detail .val-neg { color: #f66; font-weight: bold; }

.win-final-scores { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.win-final-score-item { background: rgba(0,0,0,0.3); border-radius: 8px; padding: 6px 12px; min-width: 105px; }
.win-final-score-item.winner-item { border: 1px solid #ffd700; }
.win-final-score-item.loser-item { border: 1px solid #f66; }
.win-final-score-name { font-size: 0.75em; color: #bbb; }
.win-final-score-name.winner-name { color: #ffd700; font-weight: bold; }
.win-final-score-name.loser-name { color: #f66; font-weight: bold; }
.win-final-score-pts { font-size: 0.95em; font-weight: bold; color: #fff; }
.win-final-score-change { font-size: 0.7em; }
.win-final-change-pos { color: #6f6; }
.win-final-change-neg { color: #f66; }

.gameover-banner { margin: 10px 0; padding: 10px; background: linear-gradient(135deg, #3d0a0a, #5a1515); border: 2px solid #ff4444; border-radius: 12px; }
.gameover-banner .go-title { color: #ff4444; font-size: 1.1em; font-weight: bold; letter-spacing: 2px; }
.gameover-banner .go-detail { color: #ffaaaa; font-size: 0.8em; }