:root {
  --font: "Be Vietnam Pro", Arial, sans-serif;
  --felt: #146b3a;
  --felt-dark: #0b4325;
  --rim: #5a3418;
  --gold: #f3c34b;
  --gold-dark: #b98a1c;
  --cream: #fff8ea;
  --ink: #2d1d0f;
  --red: #c8231b;
  --black: #1d1d1f;
  --win: #7cf29b;
  --lose: #ff8a7a;
  /* bề rộng lá bài trên tay: 13 lá xòe ~7.6 lá */
  --cw: min(72px, calc((100vw - 28px) / 7.7));
  --tw: min(58px, 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%, #2f2014, #170e07 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: 1040px;
  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;
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  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 {
  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;
}

/* ---------- Bàn ---------- */
.table {
  position: relative;
  overflow: hidden;
  margin: 0 8px 8px;
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255, 255, 255, 0.13), transparent 62%),
    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 6px var(--rim),
    inset 0 0 0 8px #8a5a2c,
    inset 0 0 60px rgba(0, 0, 0, 0.55),
    0 16px 40px rgba(0, 0, 0, 0.5);
}

/* ---------- Lá bài ---------- */
.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, #fff, #f1ece2);
  color: var(--black);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.25),
    0 2px 5px rgba(0, 0, 0, 0.35);
  font-weight: 800;
  user-select: none;
}
.card.red {
  color: var(--red);
}
.card .r {
  position: absolute;
  top: 4%;
  left: 7%;
  font-size: calc(var(--w) * 0.34);
  line-height: 1;
  letter-spacing: -0.04em;
}
.card .s {
  position: absolute;
  top: 31%;
  left: 8%;
  font-size: calc(var(--w) * 0.26);
  line-height: 1;
}
.card .big {
  position: absolute;
  right: 8%;
  bottom: 5%;
  font-size: calc(var(--w) * 0.56);
  line-height: 1;
  opacity: 0.9;
}
.back-card {
  width: var(--w);
  height: calc(var(--w) * 1.42);
  border-radius: calc(var(--w) * 0.12);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.14) 0 3px, transparent 3px 7px),
    linear-gradient(160deg, #b8322a, #7d1712);
  box-shadow:
    0 0 0 2px #fff,
    0 2px 5px rgba(0, 0, 0, 0.4);
}

/* ---------- Ghế máy ---------- */
.seat {
  position: absolute;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 2px;
  width: 104px;
  text-align: center;
  --w: 30px;
}
.seat.pos-top {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
}
.seat.pos-left {
  top: 24%;
  left: 14px;
}
.seat.pos-right {
  top: 24%;
  right: 14px;
}
.seat .av {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6dc, #e2c48f);
  box-shadow:
    0 0 0 3px rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(0, 0, 0, 0.4);
  font-size: 28px;
  transition: box-shadow 0.2s;
}
.seat.turn .av,
.me.turn .me-who .av {
  box-shadow:
    0 0 0 3px var(--gold),
    0 0 18px 4px rgba(243, 195, 75, 0.75);
  animation: glow 1s ease-in-out infinite alternate;
}
@keyframes glow {
  to {
    box-shadow:
      0 0 0 3px var(--gold),
      0 0 6px 1px rgba(243, 195, 75, 0.4);
  }
}
.seat .nm {
  max-width: 100%;
  overflow: hidden;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.seat .mn {
  padding: 1px 8px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--gold);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}
.seat .backs {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: 3px;
  min-height: calc(var(--w) * 1.42);
}
.seat .backs .back-card + .back-card {
  margin-left: calc(var(--w) * -0.82);
}
.seat .cnt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 26px;
  padding: 2px 6px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.75);
  font-weight: 800;
  font-size: 14px;
}
.seat .cnt.low {
  background: #c8231b;
}
.seat .open {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 150px;
  --w: 24px;
}
.seat .open .card + .card {
  margin-left: calc(var(--w) * -0.4);
}
.bubble {
  position: absolute;
  top: 6px;
  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%);
  animation: pop 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.seat.pos-top .bubble {
  top: 12px;
  left: calc(50% + 32px);
  transform: none;
}
.place {
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  font-size: 12px;
}
.place.bad {
  background: #c8231b;
  color: #fff;
}
.money-fly {
  position: absolute;
  z-index: 6;
  font-weight: 800;
  font-size: 18px;
  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.1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -54px) scale(1);
  }
}

/* ---------- Giữa bàn ---------- */
.center {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(78%, 560px);
  transform: translate(-50%, -50%);
}
.trick {
  position: relative;
  width: 100%;
  height: calc(var(--tw) * 1.42 + 18px);
}
.trick .play {
  position: absolute;
  top: 0;
  left: 50%;
  display: flex;
  transform: translateX(-50%);
  --w: var(--tw);
  transition:
    opacity 0.3s,
    transform 0.3s;
}
.trick .play .card + .card {
  margin-left: calc(var(--w) * -0.45);
}
.trick .play.old {
  opacity: 0.45;
  transform: translateX(-50%) translateY(14px) scale(0.86);
  filter: saturate(0.6);
}
.trick .play.older {
  opacity: 0;
}
.trick .play.in {
  animation: dealIn 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes dealIn {
  from {
    opacity: 0.2;
    transform: translate(calc(-50% + var(--fx, 0px)), var(--fy, 0px)) scale(0.6) rotate(var(--fr, 0deg));
  }
}
.trick-info {
  min-height: 22px;
  padding: 2px 12px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.3);
  font-weight: 700;
  font-size: 13px;
}
.trick-info:empty {
  background: none;
}
.banner {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 7;
  padding: 10px 26px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffde6b, #e19a12);
  color: #4a1d00;
  font-weight: 800;
  font-size: clamp(22px, 6vw, 34px);
  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 1px 0 rgba(0, 0, 0, 0.3);
}
@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 12px 14px;
}
.me-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 640px;
}
.me-who {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
.me-who .av {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  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: 20px;
}
.status {
  flex: 1;
  overflow: hidden;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #e9f5e4;
}
.me-delta {
  min-width: 60px;
  font-weight: 800;
  font-size: 14px;
  text-align: right;
}
.plus {
  color: var(--win);
}
.minus {
  color: var(--lose);
}
.hand {
  display: flex;
  justify-content: center;
  min-height: calc(var(--cw) * 1.42 + 14px);
  padding-top: 14px;
  --w: var(--cw);
}
.hand .card {
  cursor: pointer;
  transition: transform 0.15s;
}
.hand.dealing .card {
  animation: handIn 0.35s backwards;
}
.hand .card + .card {
  margin-left: calc(var(--w) * -0.45);
}
.hand .card.gap {
  margin-left: calc(var(--w) * -0.2);
}
.hand .card.sel {
  transform: translateY(-14px);
  box-shadow:
    0 0 0 2px var(--gold),
    0 6px 12px rgba(0, 0, 0, 0.45);
}
.hand.locked .card {
  cursor: default;
}
@keyframes handIn {
  from {
    opacity: 0;
    transform: translateY(-120px) scale(0.5) rotate(-12deg);
  }
}
.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.3fr;
  gap: 8px;
  width: 100%;
  max-width: 520px;
}

/* ---------- Nút ---------- */
.btn {
  height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: #f3e6cc;
  color: #4a3016;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 3px 0 #b99a6a;
}
.btn.primary {
  background: linear-gradient(180deg, #ffd864, var(--gold));
  color: #3d2300;
  box-shadow: 0 3px 0 var(--gold-dark);
}
.btn.big {
  height: 50px;
  font-size: 18px;
}
.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- Lớp phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 22, 12, 0.6);
  animation: fade 0.25s;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.sheet {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(100%, 380px);
  max-height: 100%;
  overflow: auto;
  padding: 20px;
  border-radius: 18px;
  background: var(--cream);
  color: var(--ink);
  box-shadow:
    0 0 0 4px #c98a45,
    0 20px 40px rgba(0, 0, 0, 0.5);
  animation: pop 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
.sheet h2 {
  margin: 0;
  font-size: 24px;
  text-align: center;
}
.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: 10px;
  background: #ead6b5;
}
.seg button {
  flex: 1;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #6b4a2b;
  font-weight: 700;
  font-size: 14px;
}
.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;
}
.broke {
  padding: 10px;
  border-radius: 10px;
  background: #ffe1d6;
  text-align: center;
}
.broke p {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 14px;
}
.stats {
  margin: 0;
  color: #7a5a3c;
  font-size: 13px;
  text-align: center;
}
.res-ico {
  font-size: 46px;
  line-height: 1;
  text-align: center;
}
.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: 6px 4px;
  border-top: 1px solid #ecdcc0;
  vertical-align: top;
}
.res-table .rk {
  width: 44px;
  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.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 1.4fr;
  gap: 8px;
}
.rules {
  width: min(100%, 520px);
  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;
}

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 560px) {
  .top {
    gap: 6px;
    padding: 6px 8px;
  }
  .top h1 {
    font-size: 17px;
  }
  .top h1 span {
    display: none;
  }
  .wallet {
    padding: 4px 9px;
    font-size: 13px;
  }
  .icon-btn {
    width: 30px;
    height: 30px;
    flex: none;
  }
  .seat .mn {
    padding: 1px 6px;
    font-size: 11px;
  }
  .back {
    font-size: 13px;
  }
  .table {
    margin: 0 4px 4px;
    border-radius: 20px;
  }
  .seat {
    width: 78px;
    --w: 22px;
  }
  .seat .av {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }
  .seat .nm {
    font-size: 12px;
  }
  .seat.pos-top {
    top: 10px;
  }
  .seat.pos-left {
    top: 26%;
    left: 8px;
  }
  .seat.pos-right {
    top: 26%;
    right: 8px;
  }
  .center {
    top: 47%;
    width: 64%;
  }
  .banner {
    top: 47%;
  }
  .actions {
    gap: 6px;
  }
  .btn {
    padding: 0 6px;
    font-size: 13px;
  }
  .me {
    padding: 0 6px 10px;
  }
}
@media (max-height: 560px) {
  .seat.pos-left,
  .seat.pos-right {
    top: 12px;
  }
  .center {
    top: 34%;
  }
}
