:root {
  --font: "Be Vietnam Pro", Arial, sans-serif;
  --felt: #157040;
  --felt-dark: #0a3f22;
  --rim: #5a3418;
  --gold: #f3c34b;
  --gold-dark: #b98a1c;
  --cream: #fff8ea;
  --ink: #2d1d0f;
  --red: #c8231b;
  --black: #1d1d1f;
  --win: #7cf29b;
  --lose: #ff8a7a;
  --plate: rgba(6, 30, 17, 0.62);
  /* bề rộng lá trên tay: 13 lá xòe ~7.6 lá */
  --cw: min(84px, calc((100vw - 28px) / 7.7));
  --tw: min(64px, calc((100vw - 40px) / 8));
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: radial-gradient(ellipse at 50% 0%, #34231a, #150d07 70%);
  font-family: var(--font);
  color: var(--cream);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button {
  font-family: var(--font);
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
  max-width: 1120px;
  margin: 0 auto;
}

/* ---------- Thanh trên ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}
.back {
  color: #f6dcb6;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}
.top h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.top h1 span {
  color: var(--gold);
  font-weight: 700;
  font-size: 15px;
}
.wallet {
  padding: 5px 12px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.45);
  box-shadow: inset 0 0 0 1px rgba(243, 195, 75, 0.5);
  font-size: 14px;
  white-space: nowrap;
}
.wallet b {
  color: var(--gold);
}
.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--cream);
  font-weight: 800;
  font-size: 15px;
  transition: background 0.2s;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ---------- Bàn ---------- */
.table {
  position: relative;
  overflow: hidden;
  margin: 0 8px 8px;
  border-radius: 34px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.14), transparent 60%),
    repeating-radial-gradient(circle at 30% 30%, rgba(0, 0, 0, 0.035) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, var(--felt), var(--felt-dark));
  box-shadow:
    inset 0 0 0 7px var(--rim),
    inset 0 0 0 9px #8a5a2c,
    inset 0 0 0 10px rgba(255, 220, 160, 0.25),
    inset 0 0 70px rgba(0, 0, 0, 0.55),
    0 16px 40px rgba(0, 0, 0, 0.5);
}
.table::before {
  /* vạch kẻ trang trí trên nỉ */
  content: "";
  position: absolute;
  inset: 26px;
  border: 2px solid rgba(255, 255, 255, 0.06);
  border-radius: 24px;
  pointer-events: none;
}
.table.shake {
  animation: shake 0.45s;
}
@keyframes shake {
  20% {
    transform: translate(-6px, 2px);
  }
  40% {
    transform: translate(5px, -3px);
  }
  60% {
    transform: translate(-4px, 1px);
  }
  80% {
    transform: translate(2px, 0);
  }
}
.felt-logo {
  position: absolute;
  top: 40%;
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 2px;
  color: rgba(255, 255, 255, 0.07);
  transform: translate(-50%, -50%);
  pointer-events: none;
  user-select: none;
}
.felt-logo b {
  font-weight: 900;
  font-size: clamp(30px, 7vw, 64px);
  letter-spacing: 0.18em;
  white-space: nowrap;
}
.felt-logo span {
  font-size: clamp(14px, 2.5vw, 22px);
  letter-spacing: 0.6em;
}
.bet-chip {
  position: absolute;
  top: 18px;
  left: 22px;
  z-index: 2;
  padding: 5px 12px 5px 8px;
  border-radius: 99px;
  background: var(--plate);
  box-shadow: inset 0 0 0 1px rgba(243, 195, 75, 0.35);
  font-weight: 700;
  font-size: 12px;
  color: #f8e7c2;
}
.bet-chip b {
  color: var(--gold);
}
.deck {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 5;
  width: 44px;
  height: 62px;
  transform: translate(-50%, -50%);
  --w: 44px;
}
.deck i {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  background: var(--back);
  box-shadow:
    inset 0 0 0 2px #fff,
    0 2px 4px rgba(0, 0, 0, 0.4);
}
.deck i:nth-child(2) {
  transform: translate(-2px, -2px);
}
.deck i:nth-child(3) {
  transform: translate(-4px, -4px);
}

/* ---------- Lá bài ---------- */
:root {
  --back:
    radial-gradient(circle at 50% 50%, #f3c34b 0 12%, #a3261c 13% 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.15) 0 2px, transparent 2px 7px),
    linear-gradient(160deg, #c53b30, #7d1712);
}
.card {
  position: relative;
  flex: none;
  width: var(--w);
  height: calc(var(--w) * 1.42);
  border-radius: calc(var(--w) * 0.1);
  background: linear-gradient(160deg, #ffffff, #f3eee4);
  color: var(--black);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.22),
    0 2px 6px rgba(0, 0, 0, 0.35);
  font-weight: 800;
  user-select: none;
  -webkit-user-select: none;
}
.card.red {
  color: var(--red);
}
/* heo: ngôi sao vàng nhỏ dưới góc số (không dùng viền để khỏi lẫn với lá đang chọn) */
.card.heo::after {
  content: "★";
  position: absolute;
  top: 47%;
  left: 9%;
  color: #d9a21e;
  font-size: calc(var(--w) * 0.2);
  line-height: 1;
}
.card .idx {
  position: absolute;
  display: grid;
  justify-items: center;
  line-height: 0.92;
}
.card .idx b {
  font-size: calc(var(--w) * 0.33);
  letter-spacing: -0.06em;
}
.card .idx i {
  font-style: normal;
  font-size: calc(var(--w) * 0.24);
}
.card .tl {
  top: 5%;
  left: 7%;
}
.card .br {
  right: 7%;
  bottom: 5%;
  transform: rotate(180deg);
}
.card .pip {
  position: absolute;
  top: 50%;
  left: 56%;
  font-size: calc(var(--w) * 0.62);
  line-height: 1;
  transform: translate(-50%, -50%);
}
.card.ace .pip {
  font-size: calc(var(--w) * 0.85);
}
.card .court {
  position: absolute;
  inset: 19% 15% 19% 26%;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: calc(var(--w) * 0.06);
  background: linear-gradient(160deg, #fff6dc, #f1dcaa);
  box-shadow:
    inset 0 0 0 1.5px color-mix(in srgb, currentColor 55%, transparent),
    inset 0 0 0 3px rgba(255, 255, 255, 0.7);
  line-height: 1;
}
.card .court em {
  font-style: normal;
  font-size: calc(var(--w) * 0.24);
  opacity: 0.85;
}
.card .court b {
  font-size: calc(var(--w) * 0.42);
}
.back-card {
  width: var(--w);
  height: calc(var(--w) * 1.42);
  border-radius: calc(var(--w) * 0.12);
  background: var(--back);
  box-shadow:
    inset 0 0 0 calc(var(--w) * 0.06) #fff,
    0 1px 4px rgba(0, 0, 0, 0.45);
}
.fly {
  position: absolute;
  z-index: 8;
  --w: 34px;
  margin: -24px 0 0 -17px;
  transition:
    transform 0.34s cubic-bezier(0.3, 0.7, 0.3, 1),
    opacity 0.34s;
  pointer-events: none;
}

/* ---------- Ghế ---------- */
.seat {
  position: absolute;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 6px;
  --w: 30px;
}
.seat.pos-top {
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
}
.seat.pos-left {
  top: 22%;
  left: 22px;
}
.seat.pos-right {
  top: 22%;
  right: 22px;
}
.plate {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 150px;
  padding: 6px 14px 6px 6px;
  border-radius: 99px;
  background: var(--plate);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 6px 16px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.25s;
}
.turn > .plate,
.me.turn .me-plate {
  box-shadow:
    inset 0 0 0 2px var(--gold),
    0 0 22px rgba(243, 195, 75, 0.45);
}
.av-wrap {
  position: relative;
  flex: none;
  width: 46px;
  height: 46px;
}
.av {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6dc, #e2c48f);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
  font-size: 26px;
}
.ring {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  transform: rotate(-90deg);
  pointer-events: none;
}
.ring circle {
  fill: none;
  stroke: var(--gold);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 157;
  stroke-dashoffset: 157;
  opacity: 0;
}
.thinking .ring circle {
  opacity: 1;
  animation: ringFill var(--think, 0.8s) linear forwards;
}
@keyframes ringFill {
  to {
    stroke-dashoffset: 0;
  }
}
.cnt {
  position: absolute;
  right: -6px;
  bottom: -4px;
  min-width: 22px;
  padding: 2px 5px;
  border-radius: 99px;
  background: #1b1b1b;
  box-shadow: 0 0 0 2px #fff8ea;
  font-weight: 800;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}
.cnt.low {
  background: var(--red);
  animation: pulse 0.9s ease-in-out infinite alternate;
}
@keyframes pulse {
  to {
    transform: scale(1.18);
  }
}
.meta {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}
.meta .nm {
  overflow: hidden;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.meta .mn {
  color: var(--gold);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}
.fan {
  position: relative;
  width: 110px;
  height: calc(var(--w) * 1.42 + 6px);
}
.fan .back-card {
  position: absolute;
  bottom: 0;
  left: 50%;
  margin-left: calc(var(--w) / -2);
  transform-origin: 50% 130%;
  transform: rotate(calc((var(--i) - (var(--k) - 1) / 2) * 7deg));
}
.open {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 180px;
  --w: 28px;
}
.open .card + .card {
  margin-left: calc(var(--w) * -0.42);
}
.bubble {
  position: absolute;
  top: -12px;
  left: 50%;
  z-index: 3;
  padding: 4px 10px;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  animation: pop 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  border: 6px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
  transform: translateX(-50%);
}
.seat.pos-top .bubble {
  top: 50%;
  left: calc(100% + 10px);
  transform: translateY(-50%);
}
.seat.pos-top .bubble::after {
  top: 50%;
  bottom: auto;
  left: -5px;
  border: 6px solid transparent;
  border-right-color: #fff;
  border-left: 0;
  transform: translateY(-50%);
}
.dots i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 1.5px;
  border-radius: 50%;
  background: currentColor;
  animation: dot 1s infinite;
}
.dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes dot {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}
.place {
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
  animation: pop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.place.bad {
  background: var(--red);
  color: #fff;
}
.money-fly {
  position: absolute;
  z-index: 9;
  font-weight: 900;
  font-size: 19px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  animation: fly 1.6s ease-out forwards;
}
.money-fly.plus {
  color: var(--win);
}
.money-fly.minus {
  color: var(--lose);
}
@keyframes fly {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.7);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -10px) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -56px) scale(1);
  }
}
@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

/* ---------- Giữa bàn ---------- */
.center {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(78%, 600px);
  transform: translate(-50%, -50%);
}
.trick {
  position: relative;
  width: 100%;
  height: calc(var(--tw) * 1.42 + 20px);
}
.trick .play {
  position: absolute;
  top: 0;
  left: 50%;
  display: flex;
  --w: var(--tw);
  transform: translateX(-50%) rotate(var(--rot, 0deg));
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.3));
  transition:
    opacity 0.35s,
    transform 0.35s,
    filter 0.35s;
}
.trick .play .card + .card {
  margin-left: calc(var(--w) * -0.42);
}
.trick .play.old {
  opacity: 0.5;
  transform: translateX(calc(-50% + var(--ox, 0px))) translateY(10px) rotate(var(--rot, 0deg)) scale(0.86);
  filter: saturate(0.5) brightness(0.85);
}
.trick .play.older {
  opacity: 0;
}
.trick .play.in {
  animation: dealIn 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
@keyframes dealIn {
  from {
    opacity: 0.3;
    transform: translate(calc(-50% + var(--fx, 0px)), var(--fy, 0px)) scale(0.55) rotate(var(--fr, 0deg));
  }
}
.trick-info {
  min-height: 24px;
  padding: 3px 14px;
  border-radius: 99px;
  background: var(--plate);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.trick-info:empty {
  visibility: hidden;
}
.trick-info b {
  color: var(--gold);
}
.banner {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 7;
  padding: 12px 28px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffe27a, #e19a12);
  color: #4a1d00;
  font-weight: 900;
  font-size: clamp(22px, 6vw, 36px);
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  box-shadow:
    0 0 0 3px #fff3c4,
    0 12px 30px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: bannerIn 1.3s ease forwards;
}
.banner.red {
  background: linear-gradient(180deg, #ff6b5b, #b0170f);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  box-shadow:
    0 0 0 3px #ffd0c8,
    0 0 40px rgba(255, 80, 60, 0.6),
    0 12px 30px rgba(0, 0, 0, 0.5);
}
@keyframes bannerIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4) rotate(-6deg);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.12) rotate(2deg);
  }
  30% {
    transform: translate(-50%, -50%) scale(1) rotate(0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70%) scale(1);
  }
}

/* ---------- Người chơi ---------- */
.me {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 0 14px 16px;
}
.me-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 760px;
}
.me-plate {
  min-width: 0;
  padding-right: 12px;
}
.me-plate .av-wrap {
  width: 38px;
  height: 38px;
}
.me-plate .av {
  font-size: 22px;
}
.status {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}
.status span {
  overflow: hidden;
  padding: 5px 14px;
  border-radius: 99px;
  background: var(--plate);
  color: #e9f5e4;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.status span.mine {
  background: linear-gradient(180deg, #ffe07a, var(--gold));
  color: #3d2300;
  box-shadow: 0 0 18px rgba(243, 195, 75, 0.55);
  animation: glowPill 1.2s ease-in-out infinite alternate;
}
@keyframes glowPill {
  to {
    box-shadow: 0 0 6px rgba(243, 195, 75, 0.3);
  }
}
.me-delta {
  min-width: 70px;
  font-weight: 900;
  font-size: 15px;
  text-align: right;
}
.plus {
  color: var(--win);
}
.minus {
  color: var(--lose);
}
.hand {
  display: flex;
  justify-content: center;
  min-height: calc(var(--cw) * 1.42 + 16px);
  padding-top: 16px;
  --w: var(--cw);
  touch-action: none;
}
.hand .card {
  cursor: pointer;
  transition:
    transform 0.16s,
    box-shadow 0.16s;
}
.hand .card + .card {
  margin-left: calc(var(--w) * -0.45);
}
.hand .card.gap {
  margin-left: calc(var(--w) * -0.18);
}
@media (hover: hover) {
  .hand .card:not(.sel):hover {
    transform: translateY(-6px);
  }
}
.hand .card.sel {
  transform: translateY(-16px);
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 14px rgba(243, 195, 75, 0.6),
    0 8px 14px rgba(0, 0, 0, 0.45);
}
.hand.reveal .card {
  animation: flipIn 0.42s backwards;
}
@keyframes flipIn {
  from {
    opacity: 0;
    transform: translateY(-30px) rotateY(90deg) scale(0.8);
  }
}
.sel-info {
  min-height: 18px;
  font-weight: 700;
  font-size: 13px;
  color: #ffe9a8;
}
.sel-info.err {
  color: #ffb3a8;
}
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.4fr;
  gap: 8px;
  width: 100%;
  max-width: 560px;
}

/* ---------- Nút ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 13px;
  background: #f3e6cc;
  color: #4a3016;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 3px 0 #b99a6a;
  transition:
    transform 0.1s,
    filter 0.2s,
    opacity 0.2s;
}
.btn i {
  font-style: normal;
  font-size: 15px;
}
.btn.primary {
  background: linear-gradient(180deg, #ffde70, var(--gold));
  color: #3d2300;
  box-shadow: 0 3px 0 var(--gold-dark);
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.12);
  color: var(--cream);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 3px 0 rgba(0, 0, 0, 0.25);
}
.btn.danger {
  background: linear-gradient(180deg, #e2604f, #b8342a);
  color: #fff;
  box-shadow: 0 3px 0 #7d1d15;
}
.btn.big {
  height: 52px;
  font-size: 18px;
}
@media (hover: hover) {
  .btn:hover:not(:disabled) {
    filter: brightness(1.08);
  }
}
.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.38;
  filter: saturate(0.3);
  cursor: default;
}
.reopen {
  position: absolute;
  bottom: 18px;
  left: 50%;
  z-index: 9;
  transform: translateX(-50%);
  box-shadow:
    0 3px 0 var(--gold-dark),
    0 10px 24px rgba(0, 0, 0, 0.45);
  animation: pop 0.3s;
}

/* ---------- Lớp phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 22, 12, 0.62);
  backdrop-filter: blur(2px);
  animation: fade 0.25s;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.sheet {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(100%, 400px);
  max-height: 100%;
  overflow: auto;
  padding: 20px;
  border-radius: 20px;
  background: var(--cream);
  color: var(--ink);
  box-shadow:
    0 0 0 4px #c98a45,
    0 20px 40px rgba(0, 0, 0, 0.5);
  animation: sheetIn 0.32s cubic-bezier(0.3, 1.4, 0.5, 1);
}
@keyframes sheetIn {
  from {
    transform: scale(0.88) translateY(10px);
    opacity: 0;
  }
}
.sheet h2 {
  margin: 0;
  font-size: 24px;
  text-align: center;
}
.lobby-sheet {
  width: min(100%, 460px);
}
.lobby-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.lobby-head h2 {
  text-align: left;
  font-size: 22px;
}
.lobby-head p {
  margin: 2px 0 0;
  color: #8b6b4b;
  font-weight: 600;
  font-size: 13px;
}
.lobby-fan {
  display: flex;
  padding-left: 12px;
}
.lobby-fan b {
  display: grid;
  place-items: center;
  width: 34px;
  height: 48px;
  margin-left: -12px;
  border-radius: 5px;
  background: #fff;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.15),
    0 2px 5px rgba(0, 0, 0, 0.25);
  color: var(--red);
  font-weight: 900;
  font-size: 16px;
  line-height: 0.9;
  transform: rotate(calc((var(--k, 0) - 1) * 12deg));
  transform-origin: 50% 120%;
}
.lobby-fan b:nth-child(1) {
  --k: 0;
}
.lobby-fan b:nth-child(2) {
  --k: 1;
}
.lobby-fan b:nth-child(3) {
  --k: 2;
}
.lobby-fan b.blk {
  color: var(--black);
}
.lobby-fan i {
  font-style: normal;
  font-size: 14px;
}
.lobby-grid,
.lobby-opts,
.lobby-side {
  display: grid;
  gap: 12px;
}
.group {
  display: grid;
  gap: 6px;
}
.group label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9a7650;
}
.seg {
  display: flex;
  padding: 3px;
  border-radius: 11px;
  background: #ead6b5;
}
.seg button {
  flex: 1;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #6b4a2b;
  font-weight: 700;
  font-size: 14px;
  transition: background 0.15s;
}
.seg button.on {
  background: #fff;
  color: #b4410f;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.seg button:disabled {
  opacity: 0.35;
  cursor: default;
}
.opps {
  display: flex;
  gap: 8px;
}
.opp {
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
  padding: 8px 4px;
  border-radius: 12px;
  background: #f5e7cc;
  font-size: 12px;
  animation: pop 0.3s;
}
.opp .av {
  width: 36px;
  height: 36px;
  font-size: 20px;
}
.opp b {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.opp span {
  color: #a0701c;
  font-weight: 700;
}
.broke {
  padding: 10px;
  border-radius: 10px;
  background: #ffe1d6;
  text-align: center;
}
.broke p {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 14px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.stats div {
  display: grid;
  gap: 1px;
  padding: 6px 2px;
  border-radius: 10px;
  background: #f5ead6;
  text-align: center;
}
.stats b {
  font-size: 15px;
}
.stats small {
  color: #8b6b4b;
  font-weight: 600;
  font-size: 10px;
}
.stats p {
  grid-column: 1 / -1;
  margin: 0;
  color: #7a5a3c;
  font-size: 13px;
  text-align: center;
}
.res-ico {
  font-size: 50px;
  line-height: 1;
  text-align: center;
  animation: bounce 0.9s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes bounce {
  from {
    transform: scale(0.2) rotate(-20deg);
  }
}
.res-sub {
  margin: -6px 0 0;
  color: #7a5a3c;
  font-weight: 600;
  text-align: center;
}
.res-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.res-table td {
  padding: 7px 4px;
  border-top: 1px solid #ecdcc0;
  vertical-align: top;
}
.res-table .rk {
  width: 46px;
  font-weight: 800;
  color: #9a7650;
}
.res-table .who {
  font-weight: 700;
}
.res-table .who small {
  display: block;
  color: #8b6b4b;
  font-weight: 600;
  font-size: 12px;
}
.res-table .amt {
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}
.res-table .amt.plus {
  color: #1d8a3f;
}
.res-table .amt.minus {
  color: #c8231b;
}
.res-table tr {
  animation: rowIn 0.4s backwards;
}
.res-table tr:nth-child(2) {
  animation-delay: 0.08s;
}
.res-table tr:nth-child(3) {
  animation-delay: 0.16s;
}
.res-table tr:nth-child(4) {
  animation-delay: 0.24s;
}
@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
}
.res-table tr.mine td {
  background: #fff1c9;
}
.res-note {
  margin: 0;
  color: #7a5a3c;
  font-size: 13px;
  text-align: center;
}
.res-note:empty {
  display: none;
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 8px;
}
.rules {
  width: min(100%, 540px);
  gap: 6px;
  font-size: 14px;
  line-height: 1.5;
}
.rules h3 {
  margin: 8px 0 0;
  font-size: 15px;
  color: #b4410f;
}
.rules p,
.rules ul {
  margin: 0;
}
.rules ul {
  padding-left: 20px;
}
.close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #ead6b5;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}
.confetti {
  position: absolute;
  inset: 0;
  z-index: 11;
  overflow: hidden;
  pointer-events: none;
}
.confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: confetti var(--dur, 2.6s) var(--delay, 0s) cubic-bezier(0.25, 0.6, 0.5, 1) forwards;
}
@keyframes confetti {
  to {
    transform: translate(var(--dx, 0px), calc(100vh + 40px)) rotate(var(--spin, 720deg));
  }
}

/* ---------- Điện thoại dọc ---------- */
@media (max-width: 600px) {
  .top {
    gap: 6px;
    padding: 6px 8px;
  }
  .top h1 {
    font-size: 17px;
  }
  .top h1 span {
    display: none;
  }
  .back {
    font-size: 13px;
  }
  .wallet {
    padding: 4px 9px;
    font-size: 13px;
  }
  .icon-btn {
    width: 30px;
    height: 30px;
  }
  .table {
    margin: 0 4px 4px;
    border-radius: 22px;
  }
  .table::before {
    inset: 14px;
    border-radius: 16px;
  }
  .bet-chip {
    top: 12px;
    left: 14px;
    font-size: 11px;
  }
  .seat {
    --w: 20px;
    gap: 4px;
  }
  .seat .plate {
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    width: 86px;
    padding: 7px 4px 6px;
    border-radius: 16px;
    text-align: center;
  }
  .seat .av-wrap {
    width: 40px;
    height: 40px;
  }
  .seat .av {
    font-size: 22px;
  }
  .seat .meta {
    justify-items: center;
    max-width: 100%;
  }
  .seat .meta .nm {
    max-width: 78px;
    font-size: 12px;
  }
  .seat .meta .mn {
    font-size: 11px;
  }
  .seat.pos-top {
    top: 40px;
  }
  .seat.pos-left {
    top: 27%;
    left: 10px;
  }
  .seat.pos-right {
    top: 27%;
    right: 10px;
  }
  .fan {
    width: 70px;
  }
  .open {
    max-width: 96px;
    --w: 20px;
  }
  .seat.pos-top .bubble {
    left: calc(100% + 6px);
  }
  .center {
    top: 52%;
    width: 64%;
  }
  .felt-logo,
  .deck,
  .banner {
    top: 52%;
  }
  .me {
    padding: 0 6px 10px;
  }
  .me-bar {
    gap: 6px;
  }
  .me-plate {
    padding: 4px 10px 4px 4px;
  }
  .me-plate .av-wrap {
    width: 30px;
    height: 30px;
  }
  .me-plate .av {
    font-size: 17px;
  }
  .me-plate .meta .nm {
    font-size: 12px;
  }
  .me-plate .meta .mn {
    font-size: 11px;
  }
  .status span {
    padding: 4px 10px;
    font-size: 12px;
  }
  .me-delta {
    min-width: 0;
    font-size: 13px;
  }
  .actions {
    gap: 6px;
  }
  .btn {
    gap: 4px;
    padding: 0 6px;
    font-size: 13px;
  }
  .btn i {
    font-size: 13px;
  }
  .row {
    grid-template-columns: 1fr 1fr;
  }
  .row .primary {
    grid-column: 1 / -1;
  }
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------- Điện thoại xoay ngang / màn thấp ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --cw: min(58px, calc((100vw - 230px) / 7.7), calc((100vh - 190px) / 1.42));
    --tw: min(44px, calc((100vh - 120px) / 5));
  }
  .top {
    padding: 4px 12px;
  }
  .top h1 {
    font-size: 16px;
  }
  .top h1 span {
    font-size: 13px;
  }
  .icon-btn {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }
  .wallet {
    padding: 3px 10px;
    font-size: 13px;
  }
  .table {
    margin: 0 6px 6px;
    border-radius: 20px;
  }
  .table::before {
    display: none;
  }
  .bet-chip {
    top: auto;
    bottom: 12px;
    left: 14px;
  }
  .seat {
    --w: 18px;
  }
  .seat .plate {
    min-width: 0;
    gap: 6px;
    padding: 4px 10px 4px 4px;
  }
  .seat .av-wrap {
    width: 32px;
    height: 32px;
  }
  .seat .av {
    font-size: 18px;
  }
  .seat .meta .nm {
    max-width: 90px;
    font-size: 12px;
  }
  .seat .meta .mn {
    font-size: 11px;
  }
  .seat .fan {
    display: none;
  }
  .seat.pos-top {
    top: 8px;
  }
  .seat.pos-left {
    top: 10px;
    left: 14px;
  }
  .seat.pos-right {
    top: 10px;
    right: 14px;
  }
  .open {
    max-width: 130px;
    --w: 18px;
  }
  .center {
    top: 33%;
    width: 50%;
    gap: 4px;
  }
  .felt-logo,
  .deck,
  .banner {
    top: 33%;
  }
  .felt-logo b {
    font-size: 36px;
  }
  .trick-info {
    min-height: 20px;
    padding: 2px 10px;
    font-size: 11px;
  }
  .me {
    grid-template-columns: 1fr 172px;
    grid-template-areas:
      "bar acts"
      "hand acts"
      "info acts";
    align-items: end;
    column-gap: 10px;
    padding: 0 12px 8px;
  }
  .me-bar {
    grid-area: bar;
    max-width: none;
  }
  .me-plate .av-wrap {
    width: 28px;
    height: 28px;
  }
  .me-plate .av {
    font-size: 16px;
  }
  .me-plate {
    padding: 3px 10px 3px 3px;
  }
  .me-plate .meta .nm,
  .me-plate .meta .mn {
    font-size: 11px;
  }
  .status span {
    padding: 3px 10px;
    font-size: 12px;
  }
  .hand {
    grid-area: hand;
    min-height: calc(var(--cw) * 1.42 + 12px);
    padding-top: 12px;
  }
  .hand .card.sel {
    transform: translateY(-11px);
  }
  .sel-info {
    grid-area: info;
    min-height: 15px;
    font-size: 11px;
  }
  .actions {
    grid-area: acts;
    grid-template-columns: 1fr 1fr;
    align-self: end;
    gap: 6px;
  }
  .btn {
    height: 38px;
    padding: 0 6px;
    font-size: 12px;
  }
  .btn.big {
    height: 44px;
  }
  .overlay {
    padding: 8px;
  }
  .sheet {
    gap: 8px;
    padding: 14px 16px;
  }
  .lobby-sheet {
    width: min(100%, 680px);
  }
  .lobby-head h2 {
    font-size: 19px;
  }
  .lobby-grid {
    grid-template-columns: 1.15fr 1fr;
    align-items: start;
  }
  .seg button {
    height: 32px;
  }
  .result-sheet {
    width: min(100%, 560px);
  }
  .res-ico {
    font-size: 34px;
  }
  .sheet h2 {
    font-size: 20px;
  }
  .res-table td {
    padding: 4px;
  }
  .reopen {
    bottom: auto;
    top: 50%;
  }
  /* ghế sát mép trên: bong bóng hiện bên dưới ô thông tin */
  .seat .bubble,
  .seat.pos-top .bubble {
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
  }
  .seat .bubble::after,
  .seat.pos-top .bubble::after {
    top: -5px;
    bottom: auto;
    left: 50%;
    border: 6px solid transparent;
    border-bottom-color: #fff;
    border-top: 0;
    transform: translateX(-50%);
  }
  .res-ico {
    font-size: 28px;
  }
  .res-sub {
    margin-top: -4px;
    font-size: 13px;
  }
  .res-table {
    font-size: 13px;
  }
  .res-table td {
    padding: 3px 4px;
  }
  .res-table .who small {
    display: inline;
    margin-left: 6px;
  }
  .btn {
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =====================================================================
   Tá lả: khu mỗi ghế (phỏm + lá đã đánh), nọc, phỏm trên tay
   ===================================================================== */
:root {
  --sw: 30px; /* lá nhỏ trên bàn */
}
.zone {
  display: grid;
  gap: 6px;
  --w: var(--sw);
}
.zone.pos-top {
  top: 14px;
  grid-template-columns: auto auto;
  align-items: start;
  justify-items: start;
}
.zone.pos-left {
  top: 17%;
  justify-items: start;
}
.zone.pos-right {
  top: 17%;
  justify-items: end;
}
.zinfo {
  display: grid;
  gap: 6px;
}
.pos-right .zinfo {
  justify-items: end;
}
.melds {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 320px;
}
.pos-right .melds {
  justify-content: flex-end;
}
.melds:empty,
.discards:empty {
  display: none;
}
.grp {
  display: flex;
  padding: 3px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.grp .card + .card {
  margin-left: calc(var(--w) * -0.48);
}
.grp.rac {
  background: rgba(200, 35, 27, 0.25);
}
.card.eaten {
  box-shadow:
    0 0 0 2px #46d18a,
    0 2px 5px rgba(0, 0, 0, 0.35);
}
.card.sent {
  box-shadow:
    0 0 0 2px #5ec8ff,
    0 2px 5px rgba(0, 0, 0, 0.35);
}
.discards {
  display: flex;
  padding: 2px;
}
.discards .card + .card {
  margin-left: calc(var(--w) * -0.3);
}
.discards .card.last {
  z-index: 1;
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 12px rgba(243, 195, 75, 0.7);
}
.discards .card.last.chot::after {
  content: "chốt";
  position: absolute;
  bottom: -14px;
  left: 50%;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  line-height: 13px;
  transform: translateX(-50%);
}
.discards .card.eatable {
  cursor: pointer;
  animation: eatPulse 0.8s ease-in-out infinite alternate;
}
@keyframes eatPulse {
  to {
    transform: translateY(-5px);
    box-shadow:
      0 0 0 3px #46d18a,
      0 0 18px rgba(70, 209, 138, 0.9);
  }
}
.pts-badge {
  align-self: center;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}
.pts-badge.mom {
  background: var(--red);
}
.my-zone {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  width: 100%;
  min-height: calc(var(--sw) * 1.42 + 6px);
  --w: var(--sw);
}
.my-zone .melds {
  max-width: none;
}

/* nọc */
.pile {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 2;
  width: 52px;
  height: 74px;
  padding: 0;
  border: 0;
  background: none;
  transform: translate(-50%, -50%);
  cursor: default;
  --w: 52px;
}
.pile i {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: var(--back);
  box-shadow:
    inset 0 0 0 3px #fff,
    0 3px 6px rgba(0, 0, 0, 0.4);
}
.pile i:nth-child(2) {
  transform: translate(-2px, -2px);
}
.pile i:nth-child(3) {
  transform: translate(-4px, -4px);
}
.pile-n {
  position: absolute;
  right: -12px;
  bottom: -8px;
  min-width: 26px;
  padding: 2px 6px;
  border-radius: 99px;
  background: #1b1b1b;
  box-shadow: 0 0 0 2px #fff8ea;
  color: #fff;
  font-weight: 800;
  font-size: 12px;
}
.pile.can {
  cursor: pointer;
  animation: pileGlow 0.9s ease-in-out infinite alternate;
}
@keyframes pileGlow {
  to {
    filter: drop-shadow(0 0 14px rgba(94, 200, 255, 0.95));
    transform: translate(-50%, -54%);
  }
}

/* phỏm trên tay: gạch màu dưới chân lá */
.hand .card[class*=" m"]::before {
  content: "";
  position: absolute;
  right: 10%;
  bottom: 4%;
  left: 10%;
  height: calc(var(--w) * 0.07);
  border-radius: 99px;
  background: var(--mc);
}
.hand .card.m0 {
  --mc: #2fae6c;
}
.hand .card.m1 {
  --mc: #2f7fd8;
}
.hand .card.m2 {
  --mc: #a052d6;
}
.hand .card.m3 {
  --mc: #e08a1e;
}

.chips {
  display: flex;
  gap: 6px;
}
.chip {
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--plate);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}
.chip:empty {
  display: none;
}
.chip.pts {
  color: #ffd27a;
}
.actions {
  grid-template-columns: 1fr 1fr 1fr 1fr 1.3fr;
  max-width: 640px;
}
.btn.blue {
  background: linear-gradient(180deg, #5fb4ff, #2f7fd8);
  color: #fff;
  box-shadow: 0 3px 0 #1d4f8a;
}
.btn.green {
  background: linear-gradient(180deg, #5fdc97, #24a35f);
  color: #fff;
  box-shadow: 0 3px 0 #146b3c;
}
.btn.nudge {
  animation: nudge 0.7s ease-in-out infinite alternate;
}
@keyframes nudge {
  to {
    transform: translateY(-3px);
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, 0.85),
      0 6px 16px rgba(0, 0, 0, 0.35);
  }
}
.res-table .pts {
  width: 52px;
  font-weight: 800;
  text-align: right;
  color: #8b6b4b;
  white-space: nowrap;
}

@media (max-width: 600px) {
  :root {
    --sw: 20px;
  }
  .zone.pos-top {
    top: 40px;
  }
  .zone.pos-left,
  .zone.pos-right {
    top: 25%;
  }
  .zone .melds {
    max-width: 104px;
  }
  .zone.pos-top .melds {
    max-width: 170px;
  }
  .pile {
    top: 50%;
    width: 42px;
    height: 60px;
  }
  .chip {
    padding: 3px 7px;
    font-size: 11px;
  }
  .chips .chip:first-child {
    display: none;
  }
  .actions {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }
  .actions .btn {
    min-width: 0;
    padding: 0 3px;
    font-size: 12px;
  }
  .actions .btn span {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .btn i {
    display: none;
  }
  .me-delta {
    display: none;
  }
  .actions #btnSort i {
    display: inline;
  }
  .actions .pre {
    display: none;
  }
  .pts-badge {
    font-size: 10px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --sw: 18px;
    --cw: min(54px, calc((100vw - 230px) / 8.2), calc((100vh - 200px) / 1.42));
  }
  .zone.pos-top {
    top: 6px;
  }
  .zone.pos-left,
  .zone.pos-right {
    top: 8px;
  }
  .zone .melds {
    max-width: 200px;
  }
  .pile {
    top: 46%;
    left: 12%;
    width: 38px;
    height: 54px;
  }
  .me {
    grid-template-areas:
      "zone acts"
      "bar acts"
      "hand acts"
      "info acts";
  }
  .my-zone {
    grid-area: zone;
    justify-content: flex-start;
    min-height: 0;
  }
  .actions {
    grid-template-columns: 1fr 1fr;
  }
  .actions .primary {
    grid-column: 1 / -1;
  }
  .chips .chip:first-child {
    display: none;
  }
}
