:root {
  --green-950: #061a14;
  --green-900: #08251c;
  --green-800: #0b3328;
  --green-700: #114b39;
  --gold: #d9b45b;
  --gold-dim: #a98a3f;
  --ivory: #f7f2e6;
  --muted: #9db8aa;
  --red: #c62828;
  --ink: #22302a;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #04120d;
  color: var(--ivory);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button {
  font-family: inherit;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(1200px 700px at 50% -10%, #155a43 0%, transparent 60%),
    radial-gradient(900px 600px at 50% 120%, #0d3428 0%, transparent 65%),
    #061a14;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(217, 180, 91, 0.18);
  background: rgba(5, 24, 18, 0.7);
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--gold);
  white-space: nowrap;
}

.brand-sub {
  font-size: 11px;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 400;
  margin-left: 8px;
}

.topbar-info {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #c9ddd2;
}

.topbar-info span {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(217, 180, 91, 0.12);
}

.conn {
  margin-left: auto;
  font-size: 12px;
  color: #8fd7b3;
  white-space: nowrap;
}

.conn.offline {
  color: #ff9a8a;
}

/* 语音开关：关闭态弱化显示 */
.btn.ghost.sound-off {
  opacity: 0.55;
}

/* ---------- 主区域 ---------- */
.table-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 12px;
  padding: 12px 16px 10px;
  min-height: 0;
}

.table {
  position: relative;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  grid-template-rows: 200px minmax(0, 1fr) 200px;
  grid-template-areas:
    ". top ."
    "left center right"
    "bottom bottom bottom";
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 46%, #17624a 0%, #114b39 45%, #0a3125 100%);
  box-shadow:
    inset 0 0 0 3px rgba(217, 180, 91, 0.18),
    inset 0 0 60px rgba(0, 0, 0, 0.45),
    var(--shadow);
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.seat {
  padding: 8px 10px;
  min-width: 0;
}

.seat-top {
  grid-area: top;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 4px 10px;
}

.seat-left {
  grid-area: left;
  display: flex;
  justify-content: center;
  align-items: center;
}

.seat-right {
  grid-area: right;
  display: flex;
  justify-content: center;
  align-items: center;
}

.seat-bottom {
  grid-area: bottom;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}

.center {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
}

/* 牌桌上的「回到结算」按钮（隐藏结算画面后出现），位于中央明置杠牌下方 */
.result-show {
  position: absolute;
  left: 50%;
  top: calc(50% + 46px);
  transform: translateX(-50%);
  z-index: 6;
}

/* ---------- 座位卡片 ---------- */
.seat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgba(3, 22, 16, 0.42);
  border: 1px solid rgba(217, 180, 91, 0.16);
  max-width: 100%;
  min-width: 0;
}

.seat-card.active {
  border-color: rgba(217, 180, 91, 0.75);
  box-shadow: 0 0 0 1px rgba(217, 180, 91, 0.45), 0 0 18px rgba(217, 180, 91, 0.18);
}

.seat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
}

.seat-name {
  font-weight: 600;
  color: var(--ivory);
}

.badge {
  font-size: 10px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  color: #b9d4c7;
}

.badge.dealer {
  background: linear-gradient(180deg, #e2c06c, #b8943f);
  color: #2a1d05;
  font-weight: 700;
}

.badge.ai {
  border: 1px solid rgba(140, 200, 175, 0.35);
  color: #9fd8bd;
  background: transparent;
}

.score {
  font-size: 12px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.score.neg {
  color: #ff8f7a;
}

.seat-sub {
  font-size: 10px;
  color: var(--muted);
}

/* ---------- 手牌 ---------- */
.hand-row {
  display: flex;
  gap: 3px;
  justify-content: center;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow: hidden;
}

.hand-row.stack {
  padding-left: 14px;
}

.hand-row.stack .tile {
  margin-left: -15px;
}

.hand-row.stack .tile:first-child {
  margin-left: 0;
}

/* 手牌行 + 自己的副露：副露固定在右下角 */
.self-bottom {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  min-width: 0;
}

.self-hand {
  /* 左对齐：新摸的牌插入手牌时，最左侧的牌位置保持不动 */
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 6px;
  justify-content: flex-start;
  align-items: flex-end;
  /* 右侧留出上家（左侧玩家）的副露区 */
  padding: 16px 8px 6px 240px;
  overflow-x: auto;
  overflow-y: visible;
  min-height: 88px;
}

.self-melds {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 16px 8px 0;
}

.self-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
  padding: 2px 10px;
}

.self-head .hint {
  font-size: 11px;
  color: var(--muted);
}

/* ---------- 牌 ---------- */
.tile {
  --tw: 44px;
  width: var(--tw);
  /* 牌面素材原图 219×292，按 0.75 宽高比显示 */
  height: calc(var(--tw) * 1.3333);
  flex: 0 0 auto;
  border-radius: 5px;
  background: linear-gradient(158deg, #fffdf7 0%, #f0e8d5 100%);
  border: 1px solid #cfc2a0;
  box-shadow: 0 2px 0 #b7aa87, 0 3px 5px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  color: var(--ink);
  font-family: "Songti SC", "STSong", "SimSun", serif;
  user-select: none;
}

.tile .num {
  font-size: calc(var(--tw) * 0.52);
  font-weight: 700;
  line-height: 1;
}

.tile .suit {
  font-size: calc(var(--tw) * 0.33);
  line-height: 1.15;
  margin-top: 2px;
  opacity: 0.9;
}

.tile.honor .num {
  font-size: calc(var(--tw) * 0.56);
}

/* 万红、条绿、筒蓝（仅调整牌面文字颜色） */
.tile[data-suit="w"] .num,
.tile[data-suit="w"] .suit {
  color: #c62828;
}

.tile[data-suit="t"] .num,
.tile[data-suit="t"] .suit {
  color: #2e7d32;
}

.tile[data-suit="b"] .num,
.tile[data-suit="b"] .suit {
  color: #1565c0;
}

.tile[data-suit="z"] .num {
  color: #2b2b2b;
}

.tile[data-code="5z"] .num {
  color: var(--red);
}

.tile[data-code="6z"] .num {
  color: #17703c;
}

.tile[data-code="7z"] .num {
  color: #1b5c8a;
}

.tile.small {
  --tw: 27px;
  box-shadow: 0 1px 0 #b7aa87, 0 2px 3px rgba(0, 0, 0, 0.25);
}

.tile.tiny {
  --tw: 22px;
  border-radius: 4px;
  box-shadow: 0 1px 0 #b7aa87, 0 1px 2px rgba(0, 0, 0, 0.22);
}

.tile.back {
  background: linear-gradient(150deg, #1f6a52 0%, #0d4132 100%);
  border-color: #0a3327;
  box-shadow: inset 0 0 0 2px rgba(217, 180, 91, 0.22), 0 2px 0 #072a21, 0 3px 5px rgba(0, 0, 0, 0.3);
}

.tile.back::after {
  content: "";
  width: 46%;
  height: 42%;
  border: 1px solid rgba(217, 180, 91, 0.55);
  border-radius: 3px;
}

.tile.hand-tile {
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.tile.hand-tile:hover {
  transform: translateY(-7px);
}

.tile.selectable {
  cursor: pointer;
}

/* 刚摸到的牌：金色描边 + 光晕，打出任意手牌后由服务端清除标记 */
.tile.drawn {
  box-shadow: 0 0 0 2px var(--gold), 0 0 12px 4px rgba(217, 180, 91, 0.75), 0 2px 0 #b7aa87;
}

/* ---------- 副露 / 塘子 ---------- */
.melds {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
}

.meld {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(217, 180, 91, 0.12);
}

.pond {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  width: fit-content;
  max-width: 100%;
  padding: 2px 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.14);
  min-height: 22px;
}

/* 每行最多 7 张，行内左对齐 */
.pond-line {
  display: flex;
  gap: 2px;
  justify-content: flex-start;
}

/* 竖排塘子（上家 / 下家）：列间留白略小，避免超出台面区域 */
.pond-left .pond,
.pond-right .pond {
  gap: 6px;
}

.pond.empty {
  background: transparent;
}

/* ---------- 座位朝向与四家分区布局 ---------- */
/* 对家：整副牌旋转 180° */
.seat-top .tile {
  transform: rotate(180deg);
}

/* 上家 / 下家：牌横躺，分别正对左侧 / 右侧观者 */
.seat-left .tile {
  transform: rotate(90deg);
}

.seat-right .tile {
  transform: rotate(-90deg);
}

/* 左右两家：卡片填满竖边，手牌竖排（牌横躺后逐张向下） */
.seat-left,
.seat-right {
  align-items: stretch;
}

/* 左右两家的牌略小一号，保证横躺后每行能放下 7 张 */
.seat-left .tile.tiny,
.seat-right .tile.tiny {
  --tw: 18px;
}

.seat-left .seat-card,
.seat-right .seat-card {
  width: 100%;
  height: 100%;
  align-items: stretch;
  justify-content: space-between;
  gap: 5px;
  padding: 6px 8px;
  overflow: hidden;
}

.seat-left .hand-row,
.seat-right .hand-row {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding-left: 0;
  gap: 0;
  /* 牌旋转后视觉宽于布局盒，需放宽裁剪 */
  overflow: visible;
}

/* 下家的手牌贴右侧桌边 */
.seat-right .hand-row {
  align-items: flex-end;
}

.seat-left .hand-row.stack .tile,
.seat-right .hand-row.stack .tile {
  margin-left: 0;
  /* 牌旋转后视觉高度小于布局占位，用负边距收紧 */
  margin-top: -10px;
}

.seat-left .hand-row.stack .tile:first-child,
.seat-right .hand-row.stack .tile:first-child {
  margin-top: 0;
}

/* 对家：卡片横向铺满，手牌居中 */
.seat-top .seat-card {
  width: 100%;
  align-items: stretch;
  gap: 3px;
  padding: 4px 10px;
}

.seat-top .hand-row {
  justify-content: center;
}

/* 左右两家的手牌不参与压缩，避免被 flex 压扁 */
.seat-left .hand-row,
.seat-right .hand-row,
.seat-top .hand-row {
  flex: 0 0 auto;
}

/* ---------- 四家塘子与四角副露（固定分区） ---------- */
.zone {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

/*
 * 塘子：以「自己」为基准——牌从左到右排列，满 7 张向下换行。
 * 其余三家由该布局旋转得到：下家逆时针 90°、对家 180°、上家顺时针 90°。
 * 区域尺寸固定，内容贴在旋转后的起始角上，保证换行/换列方向正确。
 */
.pond-zone {
  display: flex;
}

/* 自己 / 对家：横向 7 张，最多 3 行（3 行 + 行间距需 110px） */
.pond-zone.pond-top {
  width: 174px;
  height: 110px;
}

/* 自己的塘子跟随操作栏，不预留空行高度，避免压到中央信息区 */
.pond-zone.pond-bottom {
  width: 174px;
}

/* 上家 / 下家：竖向 7 张，最多 3 列（3 列 + 列间距需 84px） */
.pond-zone.pond-left,
.pond-zone.pond-right {
  width: 84px;
  height: 184px;
}

/* 自己：左上起，向右排，满了向下换行 */
.pond-zone.pond-bottom {
  left: 50%;
  transform: translateX(-50%);
  justify-content: center;
  align-items: flex-start;
}

.pond-bottom .pond {
  flex-direction: column;
  align-items: flex-start;
}

.pond-bottom .pond-line {
  flex-direction: row;
}

/* 对家：自己布局旋转 180°——右下起，向左排，满了向上换行 */
.pond-zone.pond-top {
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  justify-content: center;
  align-items: flex-end;
}

.pond-top .pond {
  flex-direction: column-reverse;
  align-items: flex-end;
}

.pond-top .pond-line {
  flex-direction: row-reverse;
}

/* 下家：自己布局逆时针旋转 90°——左下起，向上排，满了向右换列 */
.pond-zone.pond-right {
  /* 略向外、向上让位，避免与上方/自己的塘子及操作栏重叠 */
  right: 196px;
  top: calc(50% - 32px);
  transform: translateY(-50%);
  justify-content: flex-start;
  align-items: center;
}

.pond-right .pond {
  flex-direction: row;
  align-items: flex-end;
}

.pond-right .pond-line {
  flex-direction: column-reverse;
}

/* 上家：自己布局顺时针旋转 90°——右上起，向下排，满了向左换列 */
.pond-zone.pond-left {
  /* 略向外、向上让位，避免与上方/自己的塘子及操作栏重叠 */
  left: 196px;
  top: calc(50% - 32px);
  transform: translateY(-50%);
  justify-content: flex-end;
  align-items: center;
}

.pond-left .pond {
  flex-direction: row-reverse;
  align-items: flex-start;
}

.pond-left .pond-line {
  flex-direction: column;
}

/* 副露：左上对家、右上/下家、左下/上家、右下自己 */
.mz-tl {
  top: 6px;
  left: 8px;
}

.mz-tr {
  top: 6px;
  right: 8px;
}

.mz-bl {
  bottom: 6px;
  left: 8px;
}

.zone .melds,
#selfMelds .melds {
  flex-wrap: nowrap;
  justify-content: flex-start;
}

/* 对家：向右排列，行向下换行 */
.melds-top {
  flex-direction: column;
  align-items: flex-start;
}

/* 下家：向下排列，列向左换行 */
.melds-right {
  flex-direction: row-reverse;
  align-items: flex-start;
}

/* 上家：向上排列，列向右换行 */
.melds-left {
  flex-direction: row;
  align-items: flex-end;
}

.melds-left .meld-line.v {
  flex-direction: column-reverse;
}

/* 自己：向左排列，行向上换行 */
.melds-bottom {
  flex-direction: column-reverse;
  align-items: flex-end;
}

.melds-bottom .meld-line.h {
  flex-direction: row-reverse;
}

.meld-line {
  display: flex;
  gap: 6px;
}

.meld-line.v {
  flex-direction: column;
  gap: 4px;
}

/* 竖排时组内牌改为纵向堆叠 */
.melds-left .meld,
.melds-right .meld {
  flex-direction: column;
  padding: 2px 4px;
}

/* 牌面朝向与该家手牌一致 */
.pond-top .tile,
.melds-top .tile {
  transform: rotate(180deg);
}

.pond-left .tile,
.melds-left .tile {
  transform: rotate(90deg);
}

.pond-right .tile,
.melds-right .tile {
  transform: rotate(-90deg);
}

/* 竖排的塘子 / 副露用小一号牌，保证每列 7 张能放下 */
.pond-left .tile.tiny,
.pond-right .tile.tiny,
.melds-left .tile.tiny,
.melds-right .tile.tiny {
  --tw: 18px;
}

.pond-label,
.meld-label {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 1px;
}

/* ---------- 中央 ---------- */
.center-grid {
  display: flex;
  gap: 12px;
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
}

.info-box {
  min-width: 92px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(3, 22, 16, 0.4);
  border: 1px solid rgba(217, 180, 91, 0.16);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.info-box .label {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--muted);
}

.big {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.bonus-tiles {
  display: flex;
  gap: 4px;
  justify-content: center;
  min-height: 32px;
  align-items: center;
}

.bonus-tiles .placeholder {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.25);
}

.dice {
  font-size: 16px;
  color: var(--ivory);
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

.turn-hint {
  font-size: 12px;
  color: #cfe6db;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(217, 180, 91, 0.16);
  max-width: 90%;
  text-align: center;
}

.turn-hint.self {
  color: #ffe2a5;
  border-color: rgba(217, 180, 91, 0.55);
}

/* ---------- 侧栏 ---------- */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 16px;
  background: rgba(5, 24, 18, 0.72);
  border: 1px solid rgba(217, 180, 91, 0.16);
  padding: 12px;
  min-height: 0;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 1px;
}

.log-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  padding-right: 4px;
}

.log-item {
  padding: 5px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: #cfe0d6;
  line-height: 1.45;
  border-left: 2px solid rgba(217, 180, 91, 0.25);
}

.log-item.type-win {
  border-left-color: #ffb74d;
  color: #ffe2a5;
  background: rgba(217, 180, 91, 0.1);
}

.log-item.type-score {
  border-left-color: #64b5f6;
  color: #bbdefb;
}

.log-item.type-gang {
  border-left-color: #ba68c8;
  color: #e1bee7;
}

.log-item.type-discard {
  border-left-color: rgba(255, 255, 255, 0.25);
}

.log-item.type-draw {
  border-left-color: rgba(255, 255, 255, 0.12);
  color: #a9c4b7;
}

.log-item.type-start {
  border-left-color: var(--gold);
  color: #ffe9bd;
  background: rgba(217, 180, 91, 0.12);
}

.panel-foot {
  border-top: 1px solid rgba(217, 180, 91, 0.12);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rule-note {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  line-height: 1.4;
}

/* ---------- 定庄面板 ---------- */
.dictate-panel {
  position: absolute;
  left: 50%;
  top: 47%;
  transform: translate(-50%, -50%);
  z-index: 9;
  width: min(520px, 86%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 22px 16px;
  border-radius: 16px;
  background: rgba(4, 26, 19, 0.92);
  border: 1px solid rgba(217, 180, 91, 0.35);
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.dictate-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 1px;
}

.dictate-desc {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.dictate-tiles {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 6px 0 2px;
}

.dictate-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.18s ease;
}

.dictate-tile.selectable {
  cursor: pointer;
}

.dictate-tile.selectable:hover {
  transform: translateY(-6px);
}

.dictate-who {
  font-size: 11px;
  color: var(--ivory);
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dictate-tile.revealed .tile {
  box-shadow: 0 0 0 2px var(--gold), 0 0 10px 3px rgba(217, 180, 91, 0.55);
}

.dictate-timer {
  font-size: 12px;
  color: #ffd98a;
  letter-spacing: 0.3px;
}

.dictate-timer.urgent {
  color: #ff8a80;
  font-weight: 600;
}

/* ---------- 底栏操作 ---------- */
/* 自己的塘子 + 行权操作整体停靠在手牌正上方 */
.self-dock {
  position: absolute;
  left: 50%;
  bottom: 114px;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 82%;
}

.self-dock .pond-zone,
.self-dock .bottom-bar {
  position: static;
  left: auto;
  bottom: auto;
  transform: none;
}

.bottom-bar {
  width: min(540px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 16px;
  border-radius: 10px;
  background: rgba(4, 26, 19, 0.58);
  border: 1px solid rgba(217, 180, 91, 0.18);
  backdrop-filter: blur(2px);
}

.bottom-bar .turn-hint {
  padding: 0;
  background: transparent;
  border-color: transparent;
  max-width: 100%;
}

/* 提示、行权说明、倒计时合并成一行，压缩高度 */
.hint-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.turn-timer {
  font-size: 12px;
  color: #ffd98a;
  letter-spacing: 0.3px;
}

.turn-timer.urgent {
  color: #ff8a80;
  font-weight: 600;
}

.btn {
  border: 1px solid rgba(217, 180, 91, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ivory);
  padding: 9px 18px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: linear-gradient(180deg, #e2c06c, #b8943f);
  border-color: #e2c06c;
  color: #2a1d05;
  font-weight: 700;
}

.btn.gold {
  background: linear-gradient(180deg, #f0d38a, #c9a24a);
  border-color: #f0d38a;
  color: #2a1d05;
  font-weight: 700;
}

.btn.disabled,
.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

.btn .sub {
  font-size: 10px;
  opacity: 0.75;
  margin-left: 4px;
}

.action-hint {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 结算 ---------- */
.mask {
  position: fixed;
  inset: 0;
  background: rgba(2, 10, 7, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(3px);
}

.mask.hidden {
  display: none;
}

.result-card {
  width: min(560px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  background: linear-gradient(180deg, #0f3a2c, #092319);
  border: 1px solid rgba(217, 180, 91, 0.45);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: 22px 24px;
}

.result-card h2 {
  margin: 0 0 12px;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 2px;
  text-align: center;
}

.result-body {
  font-size: 13px;
  color: #d7e8df;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}

.result-fans {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.fan-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(217, 180, 91, 0.14);
  border: 1px solid rgba(217, 180, 91, 0.35);
  color: #ffe2a5;
}

.result-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- 结算：玩家牌型展示 ---------- */
.result-player {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
}

.result-player.winner {
  background: rgba(217, 180, 91, 0.12);
  border-color: rgba(217, 180, 91, 0.45);
}

.result-player-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-player-head .rp-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  color: #fff;
}

.rp-badge {
  font-size: 10px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--gold);
  color: #2a1b06;
  font-weight: 700;
}

.rp-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.rp-label {
  flex: 0 0 32px;
  font-size: 11px;
  color: var(--gold-dim);
  padding-top: 6px;
}

.rp-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: flex-end;
}

.rp-melds {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rp-meld {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

.rp-meld-type {
  font-size: 10px;
  color: var(--muted);
  margin-right: 2px;
}

.tile.win-tile {
  box-shadow: 0 0 0 2px var(--gold), 0 0 10px 3px rgba(217, 180, 91, 0.7);
}

/* ---------- 牌面素材模式（assets/tiles/*.png，219×292） ---------- */
/* 图片自带牌面、圆角与阴影，容器不再绘制牌身 */
.tile.img {
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}

.tile-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* 暗置牌改用 back.png，去掉 CSS 绘制的牌背内框 */
.tile.img.back::after {
  content: none;
}

/* 高亮改为跟随图片轮廓发光 */
.tile.img.drawn {
  box-shadow: none;
  filter: drop-shadow(0 0 3px rgba(217, 180, 91, 0.95)) drop-shadow(0 0 9px rgba(217, 180, 91, 0.75));
}

.tile.img.win-tile {
  box-shadow: none;
  filter: drop-shadow(0 0 3px rgba(217, 180, 91, 0.95)) drop-shadow(0 0 8px rgba(217, 180, 91, 0.7));
}

.win-flag {
  position: absolute;
  top: -7px;
  right: -5px;
  background: var(--gold);
  color: #2a1b06;
  font-size: 10px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: 700;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.result-row > span:first-child {
  min-width: 0;
  flex: 1;
  line-height: 1.4;
}

.result-row .delta {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.delta.pos {
  color: #7ee0a8;
}

.delta.neg {
  color: #ff9a8a;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(180, 60, 40, 0.92);
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  transition: opacity 0.2s;
}

.toast.hidden {
  display: none;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .table-wrap {
    grid-template-columns: minmax(0, 1fr);
  }
  .side-panel {
    display: none;
  }
}

@media (max-width: 760px) {
  .table {
    grid-template-columns: 84px minmax(0, 1fr) 84px;
    grid-template-rows: 100px minmax(0, 1fr) 150px;
  }
  .tile {
    --tw: 34px;
  }
  .tile.small {
    --tw: 22px;
  }
  .topbar-info {
    display: none;
  }
}

/* ==================== 多人联机：登录 / 大厅 / 房间 ==================== */

.hidden {
  display: none !important;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 700px at 50% -10%, #155a43 0%, transparent 60%),
    radial-gradient(900px 600px at 50% 120%, #0d3428 0%, transparent 65%),
    #061a14;
}

.global-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid rgba(217, 180, 91, 0.18);
  background: rgba(5, 24, 18, 0.8);
  flex: 0 0 auto;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.user-name {
  font-size: 13px;
  color: #d9e9df;
}

.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.link-btn:hover {
  background: rgba(217, 180, 91, 0.12);
}

.screen {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* ---------- 登录 / 注册 / 改密 ---------- */

.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
}

.auth-card {
  width: min(380px, 100%);
  background: linear-gradient(180deg, rgba(16, 58, 45, 0.95), rgba(7, 33, 25, 0.96));
  border: 1px solid rgba(217, 180, 91, 0.22);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 3px;
  color: var(--gold);
  text-align: center;
}

.auth-desc {
  margin: 0 0 20px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 12px;
  color: #b9d0c3;
  margin-bottom: 6px;
}

.field input,
.create-box input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(217, 180, 91, 0.22);
  background: rgba(3, 18, 13, 0.75);
  color: var(--ivory);
  font-size: 14px;
  outline: none;
}

.field input:focus,
.create-box input:focus {
  border-color: rgba(217, 180, 91, 0.65);
  box-shadow: 0 0 0 2px rgba(217, 180, 91, 0.12);
}

.form-error {
  min-height: 18px;
  font-size: 12px;
  color: #ff9a8a;
  margin: 2px 0 8px;
}

.auth-links {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.auth-links a {
  color: var(--gold);
  text-decoration: none;
}

.btn.wide {
  width: 100%;
  padding: 11px 16px;
}

.btn.small {
  padding: 5px 10px;
  font-size: 12px;
}

/* ---------- 大厅 ---------- */

.lobby {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.lobby-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.lobby-head h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: 2px;
  color: var(--gold);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.create-box {
  display: flex;
  gap: 10px;
  min-width: 320px;
  flex: 0 1 420px;
}

.create-box input {
  flex: 1;
}

.create-box .btn {
  white-space: nowrap;
}

.room-list-wrap {
  background: rgba(6, 30, 23, 0.7);
  border: 1px solid rgba(217, 180, 91, 0.16);
  border-radius: 16px;
  overflow: hidden;
}

.list-head {
  display: flex;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(217, 180, 91, 0.12);
  font-size: 13px;
  color: #d9e9df;
}

.room-list {
  display: flex;
  flex-direction: column;
}

.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.15s;
}

.room-row:last-child {
  border-bottom: none;
}

.room-row:hover {
  background: rgba(217, 180, 91, 0.08);
}

.room-row.disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.room-row.disabled:hover {
  background: none;
}

.room-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.room-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--ivory);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-code-text {
  font-size: 12px;
  color: var(--gold-dim);
  letter-spacing: 1px;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #cfe3d8;
  background: rgba(255, 255, 255, 0.06);
}

.status-pill.waiting {
  color: #8fd7b3;
  border-color: rgba(143, 215, 179, 0.4);
  background: rgba(143, 215, 179, 0.08);
}

.status-pill.playing {
  color: var(--gold);
  border-color: rgba(217, 180, 91, 0.45);
  background: rgba(217, 180, 91, 0.1);
}

.status-pill.settled {
  color: #b6c9be;
}

.empty-state {
  padding: 38px 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 房间 ---------- */

#screen-room {
  display: flex;
  flex-direction: column;
}

.room {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.room-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(217, 180, 91, 0.12);
  background: rgba(5, 24, 18, 0.55);
  flex: 0 0 auto;
}

.room-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.room-title-wrap h2 {
  margin: 0;
  font-size: 18px;
  color: var(--gold);
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-code {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
  white-space: nowrap;
}

.room-head .status-pill {
  margin-left: auto;
}

.waiting-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 26px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.seat-grid {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.room-seat {
  position: relative;
  min-height: 118px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid rgba(217, 180, 91, 0.2);
  background: linear-gradient(180deg, rgba(18, 66, 51, 0.85), rgba(8, 34, 26, 0.9));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.room-seat.empty {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.02);
  align-items: center;
  justify-content: center;
}

.room-seat.self {
  border-color: rgba(217, 180, 91, 0.7);
  box-shadow: 0 0 0 2px rgba(217, 180, 91, 0.12);
}

.room-seat-no {
  font-size: 11px;
  color: var(--gold-dim);
  letter-spacing: 1px;
}

.room-seat-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--ivory);
}

.room-seat.empty .room-seat-name {
  color: var(--muted);
  font-weight: 400;
  font-size: 14px;
}

.room-seat-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  min-height: 20px;
}

.room-seat .btn {
  align-self: flex-start;
  margin-top: 4px;
}

.badge.offline-badge {
  color: #ff9a8a;
  border-color: rgba(255, 154, 138, 0.35);
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.game-view .app {
  flex: 1;
  min-height: 0;
  height: auto;
}

.game-view .topbar {
  justify-content: space-between;
}

@media (max-width: 760px) {
  .seat-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .create-box {
    min-width: 0;
    width: 100%;
  }
  .room-head {
    flex-wrap: wrap;
  }
  .room-head .status-pill {
    margin-left: 0;
  }
}


/* ---------- 牌谱查询 ---------- */
.lobby-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.replay-search {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.replay-search input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(217, 180, 91, 0.25);
  background: rgba(4, 26, 19, 0.6);
  color: var(--ivory);
  font-size: 14px;
  outline: none;
}

.replay-search input:focus {
  border-color: var(--gold);
}

.replay-detail {
  margin: 10px 0 22px;
  padding: 18px 20px;
  border-radius: 14px;
  background: linear-gradient(180deg, #0f3a2c, #092319);
  border: 1px solid rgba(217, 180, 91, 0.35);
  box-shadow: var(--shadow);
}

.replay-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.replay-detail-head h2 {
  margin: 0;
  font-size: 18px;
  color: var(--gold);
  letter-spacing: 1px;
}

.replay-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.replay-info-row {
  display: flex;
  gap: 12px;
}

.replay-info-key {
  flex: 0 0 44px;
  color: var(--gold-dim);
}

.replay-info-val {
  color: var(--ivory);
  word-break: break-all;
}

.replay-players {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
}

.replay-player {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: #cfe3d8;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(217, 180, 91, 0.18);
}

.replay-events-title {
  margin: 16px 0 8px;
  font-size: 13px;
  color: var(--gold-dim);
}

.replay-timeline {
  max-height: 320px;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid rgba(217, 180, 91, 0.12);
  background: rgba(2, 10, 7, 0.45);
  padding: 8px 10px;
}

.replay-event {
  display: flex;
  gap: 10px;
  padding: 3px 0;
  font-size: 12px;
  line-height: 1.6;
}

.replay-event-time {
  flex: 0 0 52px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.replay-event-text {
  color: #d9e9df;
}

.result-replay {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: #cfe3d8;
  background: rgba(217, 180, 91, 0.08);
  border: 1px dashed rgba(217, 180, 91, 0.3);
}

.result-replay b {
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* ---------- 牌谱手牌快照 ---------- */
.replay-snapshot {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(2, 10, 7, 0.4);
  border: 1px solid rgba(217, 180, 91, 0.18);
}

.replay-snapshot-title {
  font-size: 13px;
  color: var(--gold-dim);
  margin-bottom: 10px;
}

.replay-snapshot-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px dashed rgba(217, 180, 91, 0.1);
}

.replay-snapshot-row:first-of-type {
  border-top: none;
}

.replay-snapshot-name {
  flex: 0 0 118px;
  font-size: 12px;
  color: var(--ivory);
  line-height: 30px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replay-snapshot-name.winner {
  color: var(--gold);
  font-weight: 600;
}

.replay-snapshot-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.replay-snapshot-tiles .tile {
  margin: 0;
}

.replay-snapshot-melds {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  flex: 0 1 auto;
}

.replay-meld {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border-radius: 8px;
  background: rgba(217, 180, 91, 0.06);
  border: 1px solid rgba(217, 180, 91, 0.16);
}

.replay-meld-label {
  font-size: 10px;
  color: var(--gold-dim);
  margin-right: 2px;
}

/* ---------- 牌谱牌墙快照 ---------- */
.replay-wall {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(2, 10, 7, 0.4);
  border: 1px solid rgba(217, 180, 91, 0.18);
}

.replay-wall-info {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 12px;
}

.replay-wall-info span {
  font-size: 11px;
  color: #c9ddd2;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(217, 180, 91, 0.12);
}

.replay-wall-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px 4px;
}

.replay-wall-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.replay-wall-no {
  font-size: 9px;
  line-height: 1;
  color: var(--muted);
}

