/* =====================================================================
   广东麻将 · 红中赖子  —— 样式
   ===================================================================== */
:root {
  --felt-1: #0d5c3a;
  --felt-2: #063a25;
  --felt-3: #0a4c31;
  --gold: #e8c164;
  --gold-dim: #a8863a;
  --ink: #1d2b24;
  --tile-face: #fffdf4;
  --tile-face-2: #efe3c6;
  --tile-edge: #c8b184;
  --red: #c62828;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  color: #eaf3ee;
  background:
    radial-gradient(circle at 50% 0%, #14563c 0%, #072a1c 60%, #04140e 100%);
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 10px 14px 6px;
  gap: 8px;
}

/* ------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand .title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(180deg, #ffe9a8, var(--gold) 60%, #b98f31);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.brand .sub { font-size: 12px; color: #9fc4b0; letter-spacing: 1px; }

.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field { font-size: 13px; color: #b9d7c7; display: flex; align-items: center; gap: 6px; }
select#difficulty {
  background: #0c3323;
  color: #ffe9a8;
  border: 1px solid #2c6b4d;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
  outline: none;
}
.btn {
  border: 1px solid #2c6b4d;
  background: #0c3323;
  color: #d7ead f;
  color: #d7eadf;
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all .16s ease;
}
.btn:hover { background: #124a33; border-color: #3f8f68; transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(180deg, #e6c368, #bb9433);
  color: #241a03;
  font-weight: 700;
  border-color: #8f6f22;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(0) scale(.98); }

/* ------------------------------------------------------- 主区域 */
.board {
  flex: 1 1 auto;
  display: flex;
  gap: 12px;
  min-height: 0;
}

.table {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr) 148px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "top top top"
    "left center right"
    "bottom bottom bottom";
  gap: 8px;
  min-height: 0;
  padding: 10px;
  border-radius: 18px;
  background:
    radial-gradient(ellipse at 50% 45%, var(--felt-3) 0%, var(--felt-1) 45%, var(--felt-2) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(232, 193, 100, .16),
    inset 0 0 60px rgba(0, 0, 0, .45),
    0 12px 30px rgba(0, 0, 0, .45);
  border: 1px solid rgba(232, 193, 100, .18);
}

/* ------------------------------------------------------- 座位 */
.seat {
  border-radius: 12px;
  padding: 6px 8px;
  background: rgba(3, 26, 17, .42);
  border: 1px solid rgba(232, 193, 100, .12);
  min-width: 0;
}
.seat-top { grid-area: top; }
.seat-left { grid-area: left; }
.seat-right { grid-area: right; }
.seat-bottom { grid-area: bottom; background: transparent; border: none; padding: 0; }

.seat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: #cfe7da;
  margin-bottom: 4px;
}
.seat-head .nm { font-weight: 700; letter-spacing: .5px; }
.seat-head .sc { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 700; }
.seat.active { box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgba(232, 193, 100, .35); }
.seat.active .seat-head .nm::before { content: "▶ "; color: var(--gold); }

.backs { display: flex; gap: 3px; flex-wrap: wrap; }
.back {
  width: 15px; height: 22px; border-radius: 3px;
  background: linear-gradient(145deg, #1a6b46, #0c3d28 60%, #0a3121);
  border: 1px solid #2f7d58;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 1px 2px rgba(0, 0, 0, .4);
}
.backs.vertical { flex-direction: column; }
.backs.vertical .back { width: 22px; height: 14px; }

.melds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.meld { display: flex; gap: 1px; padding: 2px; border-radius: 5px; background: rgba(0, 0, 0, .18); }

/* ------------------------------------------------------- 中央 */
.center {
  grid-area: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 168px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "dtop dtop dtop"
    "dleft info dright"
    "dbot dbot dbot";
  gap: 6px;
  min-height: 0;
  min-width: 0;
}
.zone-top { grid-area: dtop; }
.zone-left { grid-area: dleft; align-self: center; }
.zone-right { grid-area: dright; align-self: center; }
.zone-bottom { grid-area: dbot; }
.discard-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-content: center;
  justify-content: center;
  overflow: hidden;
  min-width: 0;
  min-height: 46px;
  padding: 4px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .10);
  border: 1px dashed rgba(232, 193, 100, .13);
}

.table-info {
  grid-area: info;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
  align-self: center;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 35%, rgba(232, 193, 100, .16), rgba(0, 0, 0, .28));
  border: 1px solid rgba(232, 193, 100, .22);
  padding: 12px 8px;
  min-width: 0;
}
.table-info .wall-left { font-size: 26px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1; }
.table-info .wall-label { font-size: 11px; color: #a9cdb9; letter-spacing: 1px; }
.table-info .round { font-size: 12px; color: #cfe7da; }
.table-info .turn {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(232, 193, 100, .16);
  color: #ffe9a8;
  border: 1px solid rgba(232, 193, 100, .3);
}
.table-info .last { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #a9cdb9; }

/* ------------------------------------------------------- 手牌 */
.hand-row { display: flex; align-items: flex-end; justify-content: center; gap: 12px; flex-wrap: wrap; }
.hand { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.hand .tile { cursor: pointer; }
.hand .tile:hover { transform: translateY(-10px); box-shadow: 0 12px 16px rgba(0, 0, 0, .5); }
.hand .tile.selected { transform: translateY(-14px); box-shadow: 0 0 0 2px var(--gold), 0 12px 16px rgba(0, 0, 0, .5); }
.hand .tile.disabled { cursor: not-allowed; opacity: .96; }
.hand .tile.disabled:hover { transform: none; box-shadow: 0 2px 0 var(--tile-edge), 0 4px 8px rgba(0,0,0,.35); }

/* ------------------------------------------------------- 牌 */
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--tile-face), var(--tile-face-2));
  border: 1px solid var(--tile-edge);
  border-radius: 7px;
  box-shadow: 0 3px 0 #b9a173, 0 4px 8px rgba(0, 0, 0, .38);
  transition: transform .13s ease, box-shadow .13s ease;
  user-select: none;
  color: var(--ink);
  overflow: hidden;
}
.tile .num { font-weight: 800; line-height: 1; }
.tile .suit { line-height: 1; }
.tile.suit0 { color: #b3541e; }   /* 万 */
.tile.suit1 { color: #1a7a45; }   /* 条 */
.tile.suit2 { color: #1d4ed8; }   /* 筒 */
.tile.laizi {
  color: var(--red);
  background: linear-gradient(180deg, #fffdf3, #ffe9b8);
  border-color: #d9a11f;
  box-shadow: 0 3px 0 #c08f18, 0 0 0 2px rgba(230, 167, 0, .45), 0 4px 10px rgba(0, 0, 0, .4);
}
.tile .badge {
  position: absolute;
  top: 1px; right: 2px;
  font-size: 8px;
  line-height: 1;
  padding: 1px 2px;
  border-radius: 3px;
  background: #d9a11f;
  color: #3a2600;
  font-weight: 800;
  transform: scale(.92);
}
.tile.big { width: 46px; height: 64px; }
.tile.big .num { font-size: 22px; }
.tile.big .suit { font-size: 15px; }
.tile.big.laizi .num { font-size: 26px; }
.tile.mid { width: 30px; height: 42px; border-radius: 5px; }
.tile.mid .num { font-size: 15px; }
.tile.mid .suit { font-size: 10px; }
.tile.small { width: 24px; height: 33px; border-radius: 4px; box-shadow: 0 2px 0 #b9a173, 0 2px 5px rgba(0,0,0,.35); }
.tile.small .num { font-size: 12px; }
.tile.small .suit { font-size: 8px; }
.tile.mini { width: 19px; height: 26px; border-radius: 3px; box-shadow: 0 1px 0 #b9a173; }
.tile.mini .num { font-size: 10px; }
.tile.mini .suit { font-size: 7px; }
.tile.newly { animation: pop .3s ease; }
.tile.win-tile { box-shadow: 0 0 0 3px #ffd54f, 0 0 16px #ffd54f; }
.tile.hint-wait { box-shadow: 0 0 0 2px #4fd1c5, 0 0 12px rgba(79, 209, 197, .8); }
@keyframes pop {
  0% { transform: translateY(-16px) scale(1.12); }
  100% { transform: translateY(0) scale(1); }
}
.tile.pop-in { animation: pop .25s ease; }

/* ------------------------------------------------------- 侧栏 */
.sidebar {
  flex: 0 0 218px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 10px;
  border-radius: 14px;
  background: rgba(3, 26, 17, .5);
  border: 1px solid rgba(232, 193, 100, .16);
}
.sidebar h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 2px;
  color: #9fc4b0;
  font-weight: 600;
  border-left: 3px solid var(--gold-dim);
  padding-left: 7px;
}
.scores { display: flex; flex-direction: column; gap: 5px; }
.score-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; font-size: 13px;
  padding: 5px 8px; border-radius: 8px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid transparent;
}
.score-row.me { border-color: rgba(232, 193, 100, .4); background: rgba(232, 193, 100, .08); }
.score-row .v { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--gold); }
.score-row .v.up { color: #6ee7a8; }
.score-row .v.down { color: #ff8b8b; }
.score-row .dot { width: 8px; height: 8px; border-radius: 50%; background: #4b7a63; margin-right: 6px; display: inline-block; }
.score-row .dot.on { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.score-row .nm { display: flex; align-items: center; }

.log {
  flex: 1 1 auto;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
  color: #bcd8c9;
  padding-right: 4px;
  min-height: 60px;
}
.log div { padding: 1px 0; border-bottom: 1px dashed rgba(255, 255, 255, .05); }
.log .hl { color: #ffe9a8; }
.log .win { color: #7ff0b0; font-weight: 700; }
.log .warn { color: #ffb4b4; }
.log::-webkit-scrollbar { width: 6px; }
.log::-webkit-scrollbar-thumb { background: #2c6b4d; border-radius: 3px; }

/* ------------------------------------------------------- 操作栏 */
.actionbar {
  position: fixed;
  left: 50%;
  bottom: 128px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
}
.actionbar.show { opacity: 1; pointer-events: auto; }
.act-btn {
  min-width: 64px;
  padding: 10px 16px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 1px;
  border-radius: 12px;
  border: 1px solid #8f6f22;
  cursor: pointer;
  color: #241a03;
  background: linear-gradient(180deg, #ffe08a, #d9ad3c);
  box-shadow: 0 4px 0 #8a6a1c, 0 8px 18px rgba(0, 0, 0, .45);
  transition: transform .1s ease, filter .15s ease;
}
.act-btn:hover { filter: brightness(1.07); transform: translateY(-2px); }
.act-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a6a1c; }
.act-btn.hu { background: linear-gradient(180deg, #ff9d7a, #e04a2f); border-color: #8c2a17; color: #fff; box-shadow: 0 4px 0 #8c2a17, 0 8px 18px rgba(0, 0, 0, .45); }
.act-btn.gang { background: linear-gradient(180deg, #9be2ff, #3aa8d8); border-color: #1d6c8c; color: #06222e; box-shadow: 0 4px 0 #1d6c8c, 0 8px 18px rgba(0, 0, 0, .45); }
.act-btn.pass { background: linear-gradient(180deg, #dfe6e3, #a9b6b0); border-color: #78837e; color: #2b342f; box-shadow: 0 4px 0 #78837e, 0 8px 18px rgba(0, 0, 0, .45); }
.timer-ring {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 800; color: #ffe9a8;
  background: conic-gradient(var(--gold) var(--p, 100%), rgba(255, 255, 255, .12) 0);
  position: relative;
}
.timer-ring::after {
  content: ""; position: absolute; inset: 4px; border-radius: 50%;
  background: #0a3626;
}
.timer-ring span { position: relative; z-index: 1; }

.hintbar {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 30;
  font-size: 13px;
  color: #ffe9a8;
  background: rgba(4, 24, 16, .82);
  border: 1px solid rgba(232, 193, 100, .3);
  padding: 5px 14px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
  max-width: 92vw;
  text-align: center;
}
.hintbar.show { opacity: 1; }

/* ------------------------------------------------------- 提示条 / 弹窗 */
.toast {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translate(-50%, -14px);
  padding: 9px 20px;
  border-radius: 999px;
  background: rgba(8, 34, 23, .95);
  border: 1px solid rgba(232, 193, 100, .45);
  color: #ffe9a8;
  font-size: 14px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: all .22s ease;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal-mask {
  position: fixed; inset: 0;
  background: rgba(2, 12, 8, .74);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-mask.show { display: flex; }
.modal-box {
  width: min(720px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #0f4530, #082b1d);
  border: 1px solid rgba(232, 193, 100, .4);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.modal-box h2 {
  margin: 0 0 12px;
  font-size: 22px;
  color: var(--gold);
  letter-spacing: 2px;
  text-align: center;
}
.modal-box h3 { font-size: 14px; color: #9fc4b0; margin: 14px 0 6px; letter-spacing: 1px; }
.modal-box p, .modal-box li { font-size: 13.5px; line-height: 1.75; color: #d6e9df; }
.modal-box ul { padding-left: 20px; margin: 6px 0; }
.modal-box .fanlist { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.fan-chip {
  padding: 4px 12px; border-radius: 999px; font-size: 13px;
  background: rgba(232, 193, 100, .14);
  border: 1px solid rgba(232, 193, 100, .38);
  color: #ffe9a8;
}
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.win-hand { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
.delta { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.delta-row { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 12px; border-radius: 8px; background: rgba(255, 255, 255, .05); }
.delta-row .plus { color: #6ee7a8; font-weight: 700; }
.delta-row .minus { color: #ff8b8b; font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv b { color: var(--gold); font-weight: 600; }

/* ------------------------------------------------------- 自适应 */
@media (max-width: 1180px) {
  .sidebar { flex: 0 0 186px; }
  .tile.big { width: 40px; height: 56px; }
  .tile.big .num { font-size: 19px; }
  .tile.big .suit { font-size: 13px; }
}
@media (max-width: 900px) {
  .board { flex-direction: column; }
  .sidebar { flex: 0 0 auto; max-height: 190px; }
  .table { grid-template-columns: 108px minmax(0, 1fr) 108px; }
  .center { grid-template-columns: minmax(0, 1fr) 120px minmax(0, 1fr); }
  .tile.big { width: 34px; height: 48px; }
  .tile.big .num { font-size: 16px; }
  .tile.big .suit { font-size: 11px; }
  .actionbar { bottom: 108px; }
}
