/* ============================================================
   Cát Tê — giao diện bàn chơi
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night-900);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background:
    radial-gradient(120% 80% at 50% -10%, #13293D 0%, #091421 45%, #050D15 100%);
}

.app {
  position: fixed;
  inset: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 6px) 0 calc(var(--safe-bottom) + 8px);
}

/* ---------------- thanh trên ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 var(--s4) var(--s2);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand__mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #1B4256, #0A2029);
  box-shadow: inset 0 0 0 1.5px rgba(228, 184, 118, .55);
  color: var(--brass-200);
  flex: none;
}
.brand__name {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--brass-100);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spacer { flex: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  border-radius: var(--r-pill);
  background: rgba(228, 184, 118, .10);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .38);
  color: var(--brass-200);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pill b { color: var(--brass-100); font-size: 14px; }

.icon-btn {
  width: 34px; height: 34px;
  border: 0;
  border-radius: 11px;
  background: rgba(228, 184, 118, .08);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .24);
  color: var(--brass-200);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ---------------- chiếu ---------------- */
.table {
  position: relative;
  flex: 1;
  margin: 0 var(--s3) var(--s2);
  border-radius: var(--r-xl);
  background:
    radial-gradient(120% 90% at 50% 0%, #14454F 0%, var(--felt-800) 45%, var(--felt-900) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(228, 184, 118, .26),
    inset 0 0 0 6px rgba(0, 0, 0, .2),
    inset 0 18px 40px rgba(0, 0, 0, .35),
    0 10px 30px rgba(0, 0, 0, .45);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--s2);
  padding: var(--s3);
  overflow: hidden;
}
.table::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.016) 0 2px, transparent 2px 5px),
    radial-gradient(85% 60% at 50% 50%, transparent 55%, rgba(0,0,0,.35) 100%);
}

/* ghế đối thủ */
.seat {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.seat--top { justify-content: center; }
.seat__info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, .28);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .18);
}
.seat__name {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  white-space: nowrap;
}
.seat__tricks {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--brass-200);
}
.seat__tricks .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brass-300);
}
.seat__tricks .dot--empty { background: rgba(255, 255, 255, .16); }
.seat--active .seat__info {
  box-shadow: inset 0 0 0 1.5px var(--brass-300), 0 0 16px rgba(228, 184, 118, .3);
}
.seat--dead .seat__name { text-decoration: line-through; opacity: .55; }
.seat--dead .seat__info { box-shadow: inset 0 0 0 1px rgba(226, 86, 76, .4); }

.seat__hand { display: flex; gap: 2px; }
.seat__hand .mini {
  width: 13px; height: 19px;
  border-radius: 3px;
  background: linear-gradient(160deg, #1B4C5E, #0A2430);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .35);
}

/* khu trung tâm */
.mid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr;
  grid-template-rows: auto 1fr auto;
  gap: var(--s2);
  align-items: center;
  justify-items: center;
}
.slot { display: grid; place-items: center; min-height: 44px; }
.slot--top { grid-area: 1 / 2; }
.slot--left { grid-area: 2 / 1; }
.slot--center { grid-area: 2 / 2; }
.slot--right { grid-area: 2 / 3; }
.slot--you { grid-area: 3 / 2; }

.round-badge {
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, .3);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .22);
  text-align: center;
}
.round-badge__n {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1;
  color: var(--brass-100);
}
.round-badge__t {
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.round-badge--chung {
  box-shadow: inset 0 0 0 1.5px var(--warn), 0 0 20px rgba(232, 165, 75, .25);
}
.round-badge--chung .round-badge__n { color: var(--warn); }

/* ---------------- lá bài ---------------- */
.card {
  position: relative;
  width: 56px; height: 78px;
  border-radius: 7px;
  background: linear-gradient(160deg, var(--card) 0%, var(--card-2) 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .7) inset,
    0 3px 8px rgba(0, 0, 0, .45);
  color: var(--black);
  overflow: hidden;
  flex: none;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.card--red { color: var(--red); }

.card__rank {
  position: absolute;
  top: 3px; left: 5px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1;
}
.card__suit {
  position: absolute;
  top: 19px; left: 5px;
  font-size: 12px;
  line-height: 1;
}
.card__big {
  position: absolute;
  right: 6px; bottom: 2px;
  font-size: 26px;
  line-height: 1;
  opacity: .9;
}

/* lá úp */
.card--back {
  background:
    repeating-linear-gradient(45deg, #123B4A 0 6px, #0E2E3A 6px 12px);
  box-shadow:
    inset 0 0 0 2px rgba(228, 184, 118, .5),
    inset 0 0 0 4px rgba(0, 0, 0, .25),
    0 3px 8px rgba(0, 0, 0, .45);
}
.card--back::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 4px;
  border: 1px solid rgba(228, 184, 118, .45);
  background: radial-gradient(circle at 50% 50%, rgba(228, 184, 118, .22), transparent 65%);
}

/* lá trên chiếu */
.card--played { transform: scale(.94); }
.card--played.card--enter { animation: card-in 260ms var(--t-slow); }
@keyframes card-in {
  from { transform: translateY(-14px) scale(.8); opacity: 0; }
  to { transform: translateY(0) scale(.94); opacity: 1; }
}

/* lá đang dẫn đầu vòng */
.card--lead {
  box-shadow:
    0 0 0 2px var(--brass-300),
    0 3px 14px rgba(228, 184, 118, .45);
}

/* ---------------- bài trên tay ---------------- */
.hand-wrap {
  padding: 0 var(--s3) var(--s2);
}
.hand {
  display: flex;
  justify-content: center;
  gap: 4px;
  min-height: 92px;
  align-items: flex-end;
}
.hand .card {
  width: 52px; height: 74px;
  transform-origin: bottom center;
}
.hand .card.is-playable {
  box-shadow:
    0 0 0 1.5px var(--brass-300),
    0 4px 12px rgba(0, 0, 0, .5);
}
.hand .card.is-playable:active { transform: translateY(-10px); }
.hand .card.is-dim { opacity: .42; filter: saturate(.6); }
.hand .card.is-taken { animation: card-out 220ms forwards; }
@keyframes card-out {
  to { transform: translateY(-40px) scale(.8); opacity: 0; }
}

/* ---------------- chân trang ---------------- */
.foot {
  padding: 0 var(--s4);
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: 46px;
}
.status {
  flex: 1;
  font-size: 13.5px;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status b { color: var(--brass-200); }
.status__spin {
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(228, 184, 118, .3);
  border-top-color: var(--brass-300);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  border: 0;
  border-radius: var(--r-md);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 18px;
  height: 42px;
  transition: transform var(--t-fast), filter var(--t-fast);
}
.btn:active { transform: translateY(1px); filter: brightness(.95); }
.btn--primary {
  color: #21160A;
  background: linear-gradient(180deg, #F7E0B4 0%, #E4B876 48%, #C08A3E 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .65), 0 3px 0 #7C5320, 0 6px 16px rgba(0, 0, 0, .4);
}
.btn--ghost {
  background: rgba(228, 184, 118, .08);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .32);
  color: var(--ink-2);
}

/* ---------------- thông báo giữa màn ---------------- */
.toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translateX(-50%) translateY(-6px);
  z-index: 30;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: rgba(5, 13, 21, .92);
  box-shadow: inset 0 0 0 1px rgba(228, 184, 118, .35);
  color: var(--brass-100);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity var(--t-mid), transform var(--t-mid);
  pointer-events: none;
  white-space: nowrap;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--good { box-shadow: inset 0 0 0 1px rgba(91, 208, 140, .6); color: #D8F7E5; }
.toast--warn { box-shadow: inset 0 0 0 1px rgba(232, 165, 75, .7); color: #FFE3B8; }

/* ---------------- kết quả ván ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  background: rgba(3, 8, 13, .68);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal[hidden] { display: none !important; }

.result-card {
  width: 100%;
  max-width: 380px;
  border-radius: var(--r-xl);
  padding: var(--s5) var(--s4) var(--s4);
  background: linear-gradient(180deg, #102436, #08141F);
  box-shadow: inset 0 0 0 1.5px rgba(228, 184, 118, .35), 0 24px 60px rgba(0, 0, 0, .6);
  text-align: center;
  animation: pop var(--t-slow);
}
@keyframes pop {
  from { transform: scale(.94); opacity: .5; }
  to { transform: scale(1); opacity: 1; }
}
.result-card__icon {
  width: 64px; height: 64px;
  margin: 0 auto var(--s3);
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 30px;
  background: rgba(228, 184, 118, .1);
  box-shadow: inset 0 0 0 1.5px rgba(228, 184, 118, .4);
}
.result-card__title {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0 0 4px;
  color: var(--brass-100);
}
.result-card__sub {
  margin: 0 0 var(--s4);
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.55;
}
.result-card__row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid rgba(228, 184, 118, .12);
  font-size: 13px;
  color: var(--ink-2);
}
.result-card__row b { color: var(--brass-200); }
.result-card .btn { width: 100%; margin-top: var(--s4); height: 48px; font-size: 15px; }

/* lá bài úp ở vòng chưng */
.card--hidden { }
.card--hidden .card__rank,
.card--hidden .card__suit,
.card--hidden .card__big { display: none; }
.card--hidden { background: repeating-linear-gradient(45deg, #123B4A 0 6px, #0E2E3A 6px 12px); color: transparent; }

/* ---------------- màn chào ---------------- */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--s6);
  background: radial-gradient(120% 90% at 50% 18%, #12384A 0%, #050D15 72%);
}
.welcome__logo {
  width: 92px; height: 92px;
  margin: 0 auto var(--s4);
  border-radius: 26px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #1D4B60, #0A2029);
  box-shadow: inset 0 0 0 2px rgba(228, 184, 118, .5), 0 16px 40px rgba(0, 0, 0, .5);
  color: var(--brass-200);
}
.welcome__title {
  font-family: var(--font-display);
  font-size: 36px;
  margin: 0 0 6px;
  color: var(--brass-100);
}
.welcome__sub {
  margin: 0 0 var(--s6);
  font-size: 13px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.welcome__btn { width: 100%; max-width: 300px; height: 54px; font-size: 16px; }

/* tiện ích */
.hidden { display: none !important; }
.center { text-align: center; }
