/* 牌桌风格:深绿台面 + 暖金描边,移动端优先,横竖屏自适应。 */
:root {
  --felt-1: #0f5132;
  --felt-2: #0a3d24;
  --gold: #e6c068;
  --gold-soft: #b89544;
  --card-w: 64px;
  --card-h: 92px;
  --ink: #1a1a1a;
  --red: #c0392b;
  --shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #f5f5f5;
  background: radial-gradient(120% 100% at 50% 0%, var(--felt-1), var(--felt-2) 70%, #06281a 100%);
  user-select: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr 1.1fr auto;
  padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom);
}

/* ---- 对家 ---- */
.opponent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  position: absolute;
  top: 10px;
}
#opp-left { left: 10px; flex-direction: row; }
#opp-right { right: 10px; flex-direction: row-reverse; }

.seat-card {
  position: relative;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--gold-soft);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 84px;
  text-align: center;
  box-shadow: var(--shadow);
}
.avatar { font-size: 24px; }
.meta { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.name { font-size: 13px; font-weight: 600; }
.cardback-count { font-size: 12px; color: var(--gold); margin-top: 2px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.landlord-badge { background: var(--gold); color: #3a2a00; font-weight: 700; display: none; }
.is-landlord .landlord-badge { display: inline-block; }

.bubble {
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: #3a2a00; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px; white-space: nowrap; opacity: 0;
  transition: opacity .2s; pointer-events: none;
}
.bubble.show { opacity: 1; }

/* ---- 中央 ---- */
#table-center {
  grid-row: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; position: relative;
}
.play-zone {
  display: flex; gap: 0; min-height: var(--card-h);
  align-items: center; justify-content: center; flex-wrap: nowrap;
}
/* 对家自带的落点已不用(所有出牌走中央区)*/
.opponent .play-zone { display: none; }
/* 中央出牌区:所有人出的牌都落这里(紧凑重叠,JS 控宽,绝不铺满)*/
.play-area {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.play-caption {
  font-size: 12px; color: var(--gold); min-height: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
/* 牌型特效:整体克制,牌型越大越亮 */
.fx-1 .play-zone .card { box-shadow: 0 0 4px 1px rgba(230,192,104,.45), var(--shadow); }
.fx-2 .play-zone .card { box-shadow: 0 0 7px 2px rgba(230,192,104,.6), var(--shadow); }
.fx-3 .play-zone .card { box-shadow: 0 0 10px 3px rgba(255,200,90,.7), var(--shadow); }
.fx-4 .play-zone .card { box-shadow: 0 0 12px 4px rgba(255,140,60,.85), var(--shadow); }
.fx-5 .play-zone .card { box-shadow: 0 0 15px 5px rgba(255,215,90,.95), var(--shadow); }
.fx-4 .play-caption, .fx-5 .play-caption { font-weight: 800; font-size: 14px; }
/* 大牌(飞机/炸弹/王炸)一次性闪光 */
.play-area::before {
  content: ""; position: absolute; left: 50%; top: 40%;
  width: 180px; height: 180px; margin: -90px 0 0 -90px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,210,120,.55), transparent 62%);
  opacity: 0; pointer-events: none;
}
.play-area.fx-burst::before { animation: fx-burst .5s ease-out; }
.play-area.fx-4.fx-burst::before { background: radial-gradient(circle, rgba(255,150,70,.7), transparent 62%); }
.play-area.fx-5.fx-burst::before { background: radial-gradient(circle, rgba(255,225,120,.8), transparent 62%); }
@keyframes fx-burst {
  0% { opacity: 0; transform: scale(.55); }
  35% { opacity: .85; }
  100% { opacity: 0; transform: scale(1.35); }
}
/* 底牌:默认停靠在桌面顶部、缩小不碍眼;地主确定时先在正中放大亮相再动画归位 */
.bottom-cards {
  position: absolute; top: 4px; left: 50%; z-index: 6;
  display: flex; gap: 4px; pointer-events: none;
  transform-origin: top center;
  transform: translate(-50%, 0) scale(.56);
  opacity: 1;
  transition: transform .55s cubic-bezier(.2,.7,.3,1), opacity .4s;
}
.bottom-cards:empty { opacity: 0; }
.bottom-cards .card { box-shadow: 0 0 0 1.5px var(--gold), var(--shadow); }
/* 底牌标签:常驻顶部作参照,亮相时随大牌下移放大 */
.bottom-label {
  position: absolute; top: 56px; left: 50%; z-index: 7;
  transform: translateX(-50%);
  font-size: 11px; font-weight: 800; letter-spacing: 1px; color: #3a2a00;
  background: linear-gradient(180deg, var(--gold), var(--gold-soft));
  padding: 1px 10px; border-radius: 10px; box-shadow: var(--shadow);
  transition: top .55s cubic-bezier(.2,.7,.3,1), font-size .4s, padding .4s;
  pointer-events: none;
}
.bottom-label.hidden { display: none; }
.bottom-label.revealing { top: calc(50% + var(--card-h) * .58); font-size: 14px; padding: 3px 14px; }
/* 倍数提示(抢/炸弹后)*/
.mult-badge {
  position: absolute; top: 2px; right: 8px; z-index: 7;
  font-size: 13px; font-weight: 800; color: #3a2a00;
  background: linear-gradient(180deg, var(--gold), var(--gold-soft));
  padding: 3px 10px; border-radius: 12px; box-shadow: var(--shadow);
}
.mult-badge.hidden { display: none; }
.bottom-cards.revealing {
  top: 50%;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}
.phase-hint {
  position: absolute; bottom: -6px; font-size: 13px; color: var(--gold);
  background: rgba(0,0,0,.3); padding: 3px 10px; border-radius: 10px;
}

/* ---- 自己 ---- */
#self { grid-row: 3; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 6px; }
#self-info { display: flex; align-items: center; gap: 8px; }
#self-name { font-size: 14px; font-weight: 600; }
#self-landlord { display: none; }
#self.is-landlord #self-landlord { display: inline-block; }

#hand {
  position: relative;
  width: 100vw;
  height: calc(var(--card-h) + 28px);
}

#actions { display: flex; gap: 10px; }
.btn {
  border: 1px solid var(--gold-soft); background: rgba(0,0,0,.35); color: #f5f5f5;
  padding: 9px 18px; border-radius: 22px; font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow); transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.95); }
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold-soft)); color: #3a2a00; border-color: var(--gold); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; filter: grayscale(.5); }
.btn.hidden { display: none; }

/* ---- 卡牌 ---- */
.card {
  position: absolute;
  width: var(--card-w); height: var(--card-h);
  background: linear-gradient(158deg, #ffffff 0%, #fff8ea 70%, #f6ecd2 100%);
  color: var(--ink);
  border: 1px solid #d8cda6; border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 4px 5px; font-weight: 700;
  transition: transform .18s ease, top .12s ease, left .12s ease, box-shadow .12s;
  will-change: transform, left, top;
}
.card::after { /* 内描边,牌面更精致 */
  content: ""; position: absolute; inset: 2px; border-radius: 5px;
  border: 1px solid rgba(0,0,0,.05); pointer-events: none;
}
.card.red { color: var(--red); }
.card .corner { font-size: 15px; line-height: .98; letter-spacing: -.5px; font-weight: 800; }
.card .corner.bottom { align-self: flex-end; transform: rotate(180deg); }
.card .pip { text-align: center; font-size: 23px; margin: -6px 0; filter: drop-shadow(0 1px 0 rgba(0,0,0,.08)); }
/* 小丑牌:丑角 SVG 居中,描边随 currentColor(大王红/小王黑)*/
.card.joker .pip.joker-face { display: flex; align-items: center; justify-content: center; margin: -2px 0; filter: none; }
.joker-svg { width: 74%; height: auto; fill: currentColor; }
.card.joker .corner { font-size: 12px; }
.card.joker-big { color: var(--red); background: linear-gradient(158deg, #ffffff, #fff1f0 75%, #ffe1de); }
.card.joker-small { color: #2c3e50; background: linear-gradient(158deg, #ffffff, #eef3f8 75%, #dfe7ef); }
.card.selected { box-shadow: 0 0 0 2px var(--gold), var(--shadow); }
.card.playable-glow { box-shadow: 0 0 10px 2px var(--gold); }

/* 牌背(对家/中央非己方使用静态布局,不绝对定位) */
.card.back, .play-zone .card, .bottom-cards .card {
  position: static;
}
.card.back {
  width: 30px; height: 44px;
  background: repeating-linear-gradient(45deg, #15532f, #15532f 4px, #0c3a20 4px, #0c3a20 8px);
  border: 1px solid var(--gold-soft);
}

/* 飞行克隆 */
.fly-clone { position: fixed; z-index: 999; pointer-events: none; transition: transform .42s cubic-bezier(.2,.7,.3,1), opacity .42s; }

/* ---- 倒计时环 ---- */
.timer-ring { position: relative; width: 40px; height: 40px; }
.timer-ring svg { transform: rotate(-90deg); }
.timer-ring .track { stroke: rgba(255,255,255,.18); }
.timer-ring .bar { stroke: var(--gold); transition: stroke-dashoffset .25s linear, stroke .25s; }
.timer-ring.warn .bar { stroke: #e2603a; }
.timer-ring .num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
}

/* ---- 弹窗/提示 ---- */
.modal { position: absolute; inset: 0; background: rgba(0,0,0,.55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-box {
  background: linear-gradient(170deg, #16472f, #0e3422 80%);
  border: 1px solid var(--gold); border-radius: 18px;
  padding: 22px 26px; min-width: 240px; text-align: center;
  box-shadow: 0 18px 48px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.06);
  animation: pop-in .22s cubic-bezier(.2,.8,.3,1.1);
}
@keyframes pop-in { 0% { opacity: 0; transform: translateY(8px) scale(.96); } 100% { opacity: 1; transform: none; } }
.modal-box h3 { margin: 0 0 14px; color: var(--gold); }

/* 决策面板(叫/抢/加倍):不变暗、不遮挡手牌,停靠在手牌上方 */
.modal.decision {
  background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none;
  align-items: flex-end; pointer-events: none;
  padding-bottom: calc(var(--card-h) + 150px);
}
.modal.decision .modal-box {
  pointer-events: auto; padding: 14px 22px; min-width: 200px;
  border-width: 2px; box-shadow: 0 10px 30px rgba(0,0,0,.55), 0 0 0 3px rgba(230,192,104,.18);
}
.modal.decision .modal-box h3 { margin: 0 0 10px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.result-row { display: flex; justify-content: space-between; gap: 18px; font-size: 15px; margin: 6px 0; }
.result-win { color: var(--gold); font-weight: 700; }
.result-detail { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--gold-soft); font-size: 12px; color: var(--gold); opacity: .85; }

/* ---- 等级称号(座位卡)---- */
.lvl-title { font-size: 11px; color: var(--gold); background: rgba(0,0,0,.25); padding: 0 6px; border-radius: 8px; }

/* ---- 地主榜 ---- */
.leaderboard-box { min-width: 300px; max-width: 92vw; }
.leaderboard-list { max-height: 56vh; overflow-y: auto; margin: 6px 0; }
.leaderboard-empty { padding: 24px; opacity: .6; }
.leaderboard-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 6px;
  border-bottom: 1px solid rgba(255,255,255,.08); cursor: pointer; text-align: left;
}
.leaderboard-row:active { background: rgba(255,255,255,.06); }
.lb-rank { width: 24px; text-align: center; font-weight: 700; color: #cfcfcf; flex: none; }
.lb-rank.rank-1 { color: #ffd24a; }
.lb-rank.rank-2 { color: #d8d8d8; }
.lb-rank.rank-3 { color: #e0a060; }
.lb-avatar { flex: none; }
.lb-name { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; font-size: 14px; }
.lb-name .lb-title { font-size: 11px; color: var(--gold); }
.lb-points { color: var(--gold); font-weight: 700; font-size: 15px; }

.toast {
  position: absolute; bottom: 30%; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.78); color: #fff; padding: 8px 16px; border-radius: 18px;
  font-size: 14px; z-index: 80; transition: opacity .2s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.conn-status {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--gold); background: rgba(0,0,0,.3);
  padding: 2px 10px; border-radius: 10px;
}
.conn-status.ok { display: none; }

/* ===================== 屏幕切换 / 头像 / 大厅 / 房间 ===================== */
.screen.hidden { display: none !important; }

/* 圆形头像(图片优先,失败/无图走首字母兜底) */
.avatar-img {
  border-radius: 50%;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; background: #444;
  flex: none; border: 2px solid var(--gold-soft);
}
.avatar-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* 登录页 / 大厅 共用大按钮 */
.btn.big { padding: 13px 30px; font-size: 17px; min-width: 210px; }

/* ---- 登录页 ---- */
.login, .lobby {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px;
}
.login-card { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.login-name { font-size: 22px; font-weight: 700; }
.login-points { color: var(--gold); font-size: 15px; }
.login-hint { font-size: 12px; opacity: .65; }

/* ---- 大厅 ---- */
.lobby-top {
  position: absolute; top: calc(env(safe-area-inset-top) + 18px); left: 20px;
  display: flex; align-items: center; gap: 10px;
}
.lobby-name { font-weight: 700; font-size: 16px; }
.lobby-points { color: var(--gold); font-size: 13px; }
.lobby-title { font-size: 26px; font-weight: 800; color: var(--gold); letter-spacing: 2px; margin-bottom: 6px; }
.lobby-actions { display: flex; flex-direction: column; gap: 14px; }
.lobby-foot { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 18px); font-size: 12px; opacity: .55; }

/* ---- 房间头(等待态)---- */
.room-header {
  position: absolute; top: calc(env(safe-area-inset-top) + 4px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; z-index: 40;
  background: rgba(0,0,0,.4); padding: 5px 12px; border-radius: 16px; border: 1px solid var(--gold-soft);
}
.room-header.hidden { display: none; }
.room-code { font-size: 13px; }
.room-code b { color: var(--gold); font-size: 17px; letter-spacing: 2px; }
.btn.mini { padding: 4px 12px; font-size: 12px; border-radius: 14px; box-shadow: none; }

/* ---- 座位卡:头像 / 房主皇冠 / 准备徽标 ---- */
.seat-card { cursor: pointer; }
.seat-card.empty { opacity: .5; }
.avatar-mount { display: flex; justify-content: center; margin-bottom: 3px; }
.host-crown { position: absolute; top: -10px; left: -6px; font-size: 16px; display: none; }
.ready-badge { background: #27ae60; color: #fff; font-weight: 700; display: none; }

/* ---- 加入房间输入框 ---- */
.code-input {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  font-size: 24px; letter-spacing: 8px; text-align: center;
  border-radius: 10px; border: 1px solid var(--gold-soft);
  background: rgba(0,0,0,.3); color: #fff; outline: none;
}
.code-input:focus { border-color: var(--gold); }

/* ---- 资料弹窗 ---- */
.profile-avatar { display: flex; justify-content: center; margin-bottom: 8px; }
.profile-stats { font-size: 14px; color: #f0f0f0; }
.lvl-chip {
  display: inline-block; margin-bottom: 10px;
  font-size: 12px; font-weight: 800; letter-spacing: 1px; color: #3a2a00;
  background: linear-gradient(180deg, var(--gold), var(--gold-soft));
  padding: 3px 14px; border-radius: 12px; box-shadow: var(--shadow);
}
.stat-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 16px;
  width: max-content; margin: 0 auto; text-align: left;
}
.stat-grid span { color: #cbd8cf; }
.stat-grid b { color: var(--gold); text-align: right; }
.profile-debt { font-size: 13px; color: #ffe6a6; margin-top: 12px; min-height: 0; }
.profile-debt b { color: var(--gold); }
.loan-action { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; }
.loan-action.hidden { display: none; }
.loan-input {
  width: 96px; padding: 7px 10px; font-size: 15px; text-align: center;
  border-radius: 10px; border: 1px solid var(--gold-soft); background: rgba(0,0,0,.3); color: #fff; outline: none;
}
.loan-input:focus { border-color: var(--gold); }
/* 顶层弹窗压住榜单 */
#profile-panel, #loan-offer-panel { z-index: 70; }
.btn.danger { background: #c0392b; border-color: #a93226; color: #fff; }

/* ---- 横/竖屏切换按钮 ---- */
.orient-toggle {
  position: absolute; top: calc(env(safe-area-inset-top) + 6px); right: 8px;
  z-index: 46; box-shadow: none; opacity: .82;
}
.orient-toggle:active { opacity: 1; }

/* ---- 强制横屏:竖屏设备上把牌桌整体旋转 90° 呈现横屏 ---- */
body.force-landscape #stage {
  position: fixed; top: 0; left: 0;
  width: 100vh; height: 100vw;            /* 交换宽高 */
  transform-origin: top left;
  transform: translateX(100vw) rotate(90deg);
}

/* ---- 横屏布局:对家贴两侧、卡牌略小、控件收紧、手牌占满 ---- */
.landscape #opp-left { top: 14px; left: 18px; }
.landscape #opp-right { top: 14px; right: 18px; }
.landscape { --card-w: 58px; --card-h: 84px; }
.landscape #stage { grid-template-rows: auto 1fr auto; padding-top: 4px; }
.landscape #table-center { gap: 4px; }
.landscape #self { gap: 4px; padding-bottom: 3px; }
.landscape #self-info { padding: 5px 9px; }
.landscape #hand { width: 100%; height: calc(var(--card-h) + 20px); }
.landscape #actions { gap: 8px; }
.landscape #actions .btn { padding: 7px 16px; font-size: 14px; }

@media (max-width: 360px) { :root { --card-w: 54px; --card-h: 78px; } }
