* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #0f1923; color: #e8eef4; -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: #8aa0b4; font-size: 13px; }

.screen { max-width: 860px; margin: 0 auto; padding: 24px 16px; }
.back-hub { display: inline-block; color: #6fc2ff; text-decoration: none; font-size: 14px; margin-bottom: 6px; }
.back-hub:hover { text-decoration: underline; }
.screen h1 { text-align: center; margin-bottom: 20px; font-size: 26px; }
.screen h2 { font-size: 16px; margin-bottom: 10px; color: #cfe0ee; }

.panel { background: #18242f; border: 1px solid #263845; border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.home-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .home-cols { grid-template-columns: 1fr; } }

label { display: block; font-size: 13px; color: #8aa0b4; margin: 8px 0 4px; }
input, select {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #34495c; background: #0f1923; color: #e8eef4; font-size: 15px; outline: none;
}
input:focus { border-color: #4d9fd6; }

.btn {
  display: inline-block; padding: 10px 16px; border-radius: 8px;
  border: 1px solid #3c5268; background: #24364a; color: #e8eef4; font-size: 15px; cursor: pointer; margin-top: 10px;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: #1f7a4d; border-color: #2a9e65; }
.btn.danger { background: #6b2530; border-color: #8d3441; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn.small { padding: 5px 10px; font-size: 13px; margin-top: 0; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; }
.row select { flex: 1; }

.room-list { max-height: 220px; overflow-y: auto; }
.room-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #263845; gap: 8px; }
.room-item .btn { margin-top: 0; padding: 6px 14px; }
.join-code { display: flex; gap: 8px; margin-top: 12px; }
.join-code .btn { margin-top: 0; }
.footer { text-align: center; margin-top: 10px; }
.share { font-size: 15px; word-break: break-all; margin-bottom: 6px; }
.share b { color: #6fc2ff; }

.player-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px; border-bottom: 1px solid #263845; font-size: 15px; }
.player-row:last-child { border-bottom: none; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #2c3f53; color: #9fc1dd; margin-left: 6px; }
.tag.host { background: #6b5424; color: #ffd97a; }
.tag.easy { background: #1f4d33; color: #8fe6b4; }
.tag.medium { background: #54481f; color: #f0d77c; }
.tag.hard { background: #5c2730; color: #ff9aa8; }


/* ===== 牌桌:居中固定舞台,不随窗口无限摊开 ===== */
.screen-game {
  max-width: none; width: 100vw; height: 100vh; padding: 0; margin: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; background: #0a121a;
}
#felt {
  position: relative; width: 100%; height: 100%; max-width: 1180px; max-height: 680px;
  border-radius: 14px;
  background:
    radial-gradient(ellipse 80% 62% at 50% 40%, #2a7a52 0%, #1d6342 55%, #134a30 100%),
    #0f1923;
  overflow: hidden;
}

/* 手机竖握:整个牌桌旋转成横屏铺满(宽高由 JS 按像素设定,避免 vw/vh 换算问题) */
body.landscape-rotate .screen-game {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
}
body.landscape-rotate { --cw: 42px; --hb: 14px; }
#felt::before { /* 桌沿光晕 */
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 0 0 120px rgba(0,0,0,.5); pointer-events: none;
}

/* 卡牌固定大小(不随窗口连续缩放,只在小屏分档);--hb 手牌离底距离
   2026-07-29:手牌放大并上移(--cw 48→58、--hb 26→40) */
:root { --cw: 58px; --hb: 40px; }
@media (max-width: 860px) { :root { --cw: 46px; --hb: 30px; } }
@media (max-width: 640px) { :root { --cw: 34px; --hb: 16px; } }

#g-topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 44px; z-index: 8;
  display: flex; align-items: center; justify-content: space-between; padding: 8px 12px;
}
#ddz-info { color: #e7f3ec; font-size: 13px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.g-pill {
  border: none; border-radius: 16px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  background: rgba(0,0,0,.35); color: #fff; border: 1px solid rgba(255,255,255,.25);
}
.g-pill.danger { background: rgba(140,40,52,.7); }
.g-pill:active { transform: scale(.96); }

/* 扑克牌(2026-07-29 美化版):左上角「点数+花色」+ 右下角大花色水印,
   象牙白渐变底 + 细内框,王牌带🃏。高度按自身宽度算(修复 mini 牌被拉长) */
.card {
  width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: calc(var(--cw) * .13);
  background: linear-gradient(160deg, #ffffff 0%, #fbfaf4 55%, #f0eee2 100%);
  color: #1c1c22;
  box-shadow: 0 1px 4px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.8);
  position: relative; flex: 0 0 auto;
  overflow: hidden; user-select: none; font-weight: 800;
}
.card::after { /* 细内框,一点"印刷感" */
  content: ""; position: absolute; inset: calc(var(--cw) * .05);
  border: 1px solid rgba(60, 70, 90, .12); border-radius: calc(var(--cw) * .09);
  pointer-events: none;
}
.card .idx {
  position: absolute; top: calc(var(--cw) * .04); left: calc(var(--cw) * .07);
  display: flex; flex-direction: column; align-items: center; line-height: .82; z-index: 1;
}
.card .idx .r { font-size: calc(var(--cw) * .5); }
.card .idx .s { font-size: calc(var(--cw) * .44); }
.card .pip { /* 右下角大花色水印 */
  position: absolute; right: calc(var(--cw) * .07); bottom: calc(var(--cw) * .03);
  font-size: calc(var(--cw) * .58); line-height: 1; opacity: .85; pointer-events: none;
}
.card.red { color: #d8252f; }
.card.red .pip { text-shadow: 0 1px 2px rgba(216,37,47,.18); }
.card .jk {
  position: absolute; top: calc(var(--cw) * .06); left: 0; right: 0;
  margin: 0 auto; width: 1em;
  writing-mode: vertical-rl; text-orientation: upright;
  font-size: calc(var(--cw) * .3); letter-spacing: 0; font-weight: 800;
}
.card.joker-s, .card.joker-b { background: linear-gradient(160deg, #fffef7 0%, #fdf6df 60%, #f4e9c8 100%); }
.card.joker-s { color: #232330; }
.card.joker-b { color: #d8252f; }
.card.joker-s .pip, .card.joker-b .pip { font-size: calc(var(--cw) * .5); opacity: 1; }
.card.mini { --cw: 34px; }
@media (max-width: 640px) { .card.mini { --cw: 28px; } }
.role-landlord { color: #ffd34d; font-weight: 700; }
.role-farmer { color: #8fe6b4; font-weight: 700; }

/* 地主底牌 */
#bottom-cards { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; z-index: 6; }

/* 对手座位:头像信息 + 牌背叠放 */
.oppseat { position: absolute; top: 58px; width: 180px; z-index: 5; }
#seat-left { left: 14px; }
#seat-right { right: 14px; }
.oppseat .ohead { display: flex; align-items: center; gap: 8px; }
#seat-right .ohead { flex-direction: row-reverse; text-align: right; }
.oppseat .avatar {
  width: 48px; height: 48px; border-radius: 50%; font-size: 26px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3a5570, #24384a);
  border: 2px solid #cdd9e6; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.oppseat .pinfo { overflow: hidden; }
.oppseat .pname { font-size: 14px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oppseat .pcoins { font-size: 12px; color: #ffd97a; }
.oppseat .prole { font-size: 15px; }
.oppseat.turn .avatar { border-color: #ffd34d; box-shadow: 0 0 14px #ffd34d; }
/* 牌背叠放 + 张数 */
.cardstack { display: flex; align-items: center; margin-top: 6px; height: calc(var(--cw) * .82); }
#seat-right .cardstack { flex-direction: row-reverse; }
.cardstack .cb {
  width: calc(var(--cw) * .5); height: calc(var(--cw) * .82); border-radius: 3px; flex: 0 0 auto;
  margin-left: calc(var(--cw) * -0.34);
  background: repeating-linear-gradient(45deg, #2f63a6, #2f63a6 3px, #244f86 3px, #244f86 6px);
  border: 1px solid #d3dbe6; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.cardstack .cb:first-child { margin-left: 0; }
#seat-right .cardstack .cb { margin-left: 0; margin-right: calc(var(--cw) * -0.34); }
#seat-right .cardstack .cb:first-child { margin-right: 0; }
.cardstack .cnt {
  margin: 0 6px; background: rgba(0,0,0,.6); border-radius: 12px; padding: 2px 11px;
  font-size: 18px; color: #ffe08a; font-weight: 800; flex: 0 0 auto;
}

/* 出牌展示区:左 / 右 / 我自己
   z-index 高于对手座位(5):出的牌永远显示在最上面,不被头像/牌背遮挡
   2026-07-29:改为"贴着中线左右分列",两边各自朝中间对齐 → 更居中,且天然不会互相重叠 */
/* max-width + flex-wrap:12 张顺子这类超长牌型自动折行,永远不会撑出屏幕 */
.playzone {
  position: absolute; z-index: 6; display: flex; gap: 3px; align-items: center;
  min-height: calc(var(--cw) * 1.0); flex-wrap: wrap; max-width: 46%; row-gap: 2px;
}
/* 2026-07-29 二次调整:两家的牌回到各自那一侧(都挤在中线会分不清谁出的),
   左家从左侧19%起向右排,右家从右侧19%起向左排 */
/* 19%起 + 上限29% → 各自占 19%~48% / 52%~81%,中间留空,两家永不相撞;
   超长牌型(如12张顺子)会自动折行,也不会盖住对手座位的"剩余张数"徽章 */
/* top 150→240:牌放大后要往下挪约一个牌高,才不会贴住上方座位/文字 */
#play-left { left: 19%; top: 240px; justify-content: flex-start; max-width: 29%; }
#play-right { right: 19%; top: 240px; justify-content: flex-end; max-width: 29%; }
/* 打出的牌(含我方)再放大 1.5 倍:41→62px(2026-07-29 用户要求) */
.playzone .card.mini { --cw: 62px; }
/* 9 张以上的长牌型(顺子/连对/飞机)自动缩小,保持单行——竖向空间放不下两行,
   折行会撞到自己出的牌。缩小比折行更好看,点数也不会被裁掉 */
.playzone:has(.card:nth-child(9)) .card.mini { --cw: 50px; }
@media (max-width: 860px) {
  #play-left, #play-right { top: 200px; }
  .playzone .card.mini { --cw: 50px; }
  .playzone:has(.card:nth-child(9)) .card.mini { --cw: 40px; }
}
/* 出的牌略微叠放成扇形:点数在左上角不会被挡,同时保证顺子等长牌型不会撑出屏幕 */
.playzone { gap: 0; }
.playzone .card + .card { margin-left: calc(var(--cw) * -0.2); }
@media (max-width: 640px) {
  /* 手机牌桌只有 375 高,放大幅度必须收着来,否则上下会互相挤 */
  #play-left, #play-right { top: 100px; }
  .playzone .card.mini { --cw: 38px; }
  /* 27px 是 12 张顺子还能挤进单行的上限(27×8.26≈223 < 235 的横向空间),再大就会折行撞到自己出的牌 */
  .playzone:has(.card:nth-child(9)) .card.mini { --cw: 27px; }
  .playzone .card + .card { margin-left: calc(var(--cw) * -0.34); }
  #ddz-actions { gap: 20px; }  /* 手机屏窄,间距比电脑端小一些 */
}
#play-me { left: 50%; transform: translateX(-50%); bottom: calc(var(--hb) + var(--cw) * 1.4 + 96px); }
.playzone .pass-bubble {
  background: rgba(245,248,255,.92); color: #3a5570; font-weight: 700; font-size: 15px;
  padding: 5px 16px; border-radius: 16px; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

/* 我(左侧空白区,不再压住手牌) */
#me-corner {
  position: absolute; left: 12px; bottom: calc(var(--hb) + var(--cw) * 1.4 + 62px); z-index: 7; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.18);
  border-radius: 30px; padding: 4px 14px 4px 4px;
}
#me-corner .avatar {
  width: 46px; height: 46px; border-radius: 50%; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg,#5a3a70,#3a2450); border: 2px solid #d6b8ff; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
#me-corner .pname { font-size: 14px; font-weight: 600; color: #fff; }
#me-corner .pcoins { font-size: 12px; color: #ffd97a; }
#me-corner .prole { font-size: 15px; }
#me-corner.turn .avatar { border-color: #ffd34d; box-shadow: 0 0 14px #ffd34d; }

/* 我的手牌 */
#my-hand {
  position: absolute; left: 0; right: 0; bottom: var(--hb); z-index: 6;
  display: flex; justify-content: center; align-items: flex-end;
  padding: 0 12px; touch-action: none; min-height: calc(var(--cw) * 1.4);
}
#my-hand .card { margin-left: calc(var(--cw) * -0.4); cursor: pointer; transition: transform .08s; }
#my-hand .card:first-child { margin-left: 0; }
/* 选中只上移,不抬层级,避免盖住相邻未选牌的角标;加金色描边更醒目 */
#my-hand .card.sel {
  transform: translateY(-20px);
  box-shadow: 0 0 0 2px #ffd34d, 0 6px 14px rgba(0,0,0,.45);
}

/* 操作区(不出 / 倒计时 / 提示 / 出牌)— 按钮固定大小,只调间距
   2026-07-29:+14px→+38px。选中的牌会上抬 20px,原来的高度会被按钮压住(用户反馈) */
#ddz-actions {
  position: absolute; left: 50%; bottom: calc(var(--hb) + var(--cw) * 1.4 + 38px); transform: translateX(-50%);
  display: flex; gap: 34px; align-items: center; z-index: 7;  /* 16→34:按钮别挤成一团 */
}
.act-btn {
  border: none; cursor: pointer; color: #fff; font-size: 16px; font-weight: 700;
  width: 92px; padding: 11px 0; text-align: center; border-radius: 24px;
  box-shadow: 0 3px 0 rgba(0,0,0,.25), 0 4px 10px rgba(0,0,0,.3);
  background: linear-gradient(#5b8def, #3a63c8); flex: 0 0 auto;
}
.act-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.act-btn.play { background: linear-gradient(#ffb24d, #f08a1e); }
.act-btn.pass { background: linear-gradient(#9aa6b4, #6f7d8c); }
.act-btn.bid3 { background: linear-gradient(#ff7a7a, #e23d3d); }
.act-btn:disabled { opacity: .45; cursor: not-allowed; }
.timer-badge {
  width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: #fff;
  background: radial-gradient(circle at 50% 40%, #ffcf5a, #e8961f); border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.bid-label { color: #fff; font-size: 15px; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
#ddz-actions .waiting { color: #e7f3ec; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }

/* 信息框(右下角小内容框,置于底层;靠右,避开居中的手牌与中间出牌区) */
#info-box {
  position: absolute; right: 6px; bottom: var(--hb); z-index: 3; width: 152px; height: calc(var(--cw) * 1.4);
  background: rgba(8,16,24,.5); border: 1px solid rgba(255,255,255,.14); border-radius: 8px;
  padding: 4px 8px; overflow: hidden;
}
#info-lines { height: 100%; overflow-y: auto; font-size: 11px; line-height: 1.45; color: #e0ecdf; word-break: break-all; }

#ddz-banner {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%);
  background: rgba(8,14,20,.95); border: 1px solid #ffd34d; border-radius: 14px;
  padding: 18px 26px; text-align: center; font-size: 20px; z-index: 20; box-shadow: 0 6px 36px rgba(0,0,0,.7);
  max-width: 92vw;
}
#ddz-banner .sub { font-size: 14px; color: #ffd97a; margin-top: 8px; }
#ddz-banner .reveal { margin-top: 12px; font-size: 12px; color: #b8cadb; line-height: 1.5; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#ddz-banner .reveal .row { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; justify-content: center; }
#ddz-banner .reveal .nm { color: #cfe0ee; margin-right: 4px; }
/* 结算亮牌:标题 + 牌放大一点,方便复盘"对手手里还剩什么" */
#ddz-banner .reveal-title { margin-top: 12px; font-size: 13px; color: #ffd97a; font-weight: 700; }
#ddz-banner .reveal .card.mini { --cw: 30px; }
#ddz-banner .reveal .row { margin-top: 4px; }

/* ===== 顶栏右侧按钮组 ===== */
.topbar-right { display: flex; gap: 8px; align-items: center; }

/* ===== 设置面板 ===== */
#settings-panel {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 30; width: 260px;
  background: rgba(10,18,26,.96); border: 1px solid #3c5268; border-radius: 14px;
  padding: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
/* 注:设置面板/记牌器在 #felt 内部,会跟着牌桌一起旋转,不需要再单独转 */
.sp-title { font-size: 16px; font-weight: 700; color: #e8eef4; margin-bottom: 12px; text-align: center; }
.sp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid #263845; color: #e8eef4; font-size: 15px; cursor: pointer;
}
.sp-row small { display: block; color: #8aa0b4; font-size: 11px; margin-top: 2px; }
.sp-row input[type=checkbox] { width: 46px; height: 26px; flex: 0 0 auto; cursor: pointer; accent-color: #2a9e65; }
#settings-panel .btn { width: 100%; }

/* ===== 记牌器面板 ===== */
/* 放在右下角、信息框正上方:牌桌中段要留给出牌区,这里是唯一两种屏幕尺寸都稳定空着的位置 */
/* 2026-07-29 重做:原来挤成一片数字看不明白。改为「标题 + 5列×3行规整网格」,
   每格独立底色、点数在上剩余张数在下,并按剩余量分级配色 */
#counter-panel {
  position: absolute; right: 6px; bottom: calc(var(--hb) + var(--cw) * 1.4 + 10px); z-index: 9;
  width: 212px; padding: 7px 8px 8px;
  background: rgba(8,16,26,.9); border: 1px solid rgba(255,255,255,.22); border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.45); pointer-events: none;
}
.cnt-title {
  font-size: 11px; color: #9fc1dd; text-align: center; letter-spacing: .5px;
  padding-bottom: 5px; margin-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,.14);
}
.cnt-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.cnt-cell { background: rgba(255,255,255,.08); border-radius: 6px; padding: 3px 0 4px; text-align: center; }
.cnt-cell .rk { font-size: 11px; color: #b8cadb; line-height: 1.15; font-weight: 600; }
.cnt-cell .nb { font-size: 16px; font-weight: 800; color: #8fe6b4; line-height: 1.2; }
.cnt-cell.gone { background: rgba(255,255,255,.03); }              /* 已出完:整格变暗 */
.cnt-cell.gone .rk, .cnt-cell.gone .nb { color: #4d5c6b; }
.cnt-cell.few { background: rgba(255,211,77,.16); }                 /* 只剩1张:黄底提醒 */
.cnt-cell.few .nb { color: #ffd34d; }
.cnt-cell.joker { background: rgba(255,190,106,.16); }              /* 大小王单独配色 */
.cnt-cell.joker .rk { color: #ffbe6a; }
@media (max-width: 640px) {
  #counter-panel { width: 168px; padding: 5px 6px 6px; }
  .cnt-title { font-size: 9.5px; padding-bottom: 3px; margin-bottom: 4px; }
  .cnt-grid { gap: 3px; }
  .cnt-cell { padding: 2px 0 3px; }
  .cnt-cell .rk { font-size: 9.5px; }
  .cnt-cell .nb { font-size: 13px; }
}

#toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  background: #6b2530; border: 1px solid #8d3441; color: #fff; padding: 9px 18px; border-radius: 9px;
  font-size: 14px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }
/* 手机竖握旋转模式:提示气泡/结算横幅跟着牌桌一起转 90°,
   否则它们按"未旋转的世界"定位,会歪着出现在玩家视角的左右两侧(2026-07-29 用户反馈) */
body.landscape-rotate #toast {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
}
body.landscape-rotate #ddz-banner {
  transform: translate(-50%, -50%) rotate(90deg);
}
#disconnected { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200; display: flex; align-items: center; justify-content: center; }

@media (max-width: 640px) {
  .oppseat { width: 130px; }
  .oppseat .avatar, #me-corner .avatar { width: 40px; height: 40px; font-size: 20px; }
  .act-btn { padding: 9px 16px; font-size: 14px; }
  #info-box { width: 150px; }
}
