:root {
  --bg: #0b2e20;
  --bg2: #124a33;
  --card: #f9f6ee;
  --ink: #1f2a24;
  --light: #f4efe2;
  --muted: #8fa89a;
  --line: rgba(255, 255, 255, .14);
  --accent: #f2c14e;
  --accent-ink: #3b2a00;
  --red: #e53935;
  --good: #66bb6a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0, var(--bg2) 0, var(--bg) 70%) fixed;
  color: var(--light);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1 { text-align: center; margin: 28px 0 4px; font-size: 38px; letter-spacing: .02em; }
h1 .suits { display: block; font-size: 26px; letter-spacing: .3em; color: var(--light); opacity: .9; }
h1 .suits i { font-style: normal; color: var(--red); }
h2 { font-size: 15px; margin: 18px 0 8px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.app-version { text-align: center; color: var(--muted); font-size: 11px; margin: -12px 0 16px; opacity: .7; }
.hint { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--good); font-weight: 800; }
.down { color: #ff7961; font-weight: 800; }

input, button {
  font: inherit; border-radius: 12px; border: 1px solid var(--line);
  padding: 11px 14px; background: rgba(255, 255, 255, .08); color: var(--light);
}
input { width: 100%; }
input::placeholder { color: var(--muted); }
button { cursor: pointer; font-weight: 700; box-shadow: 0 3px 0 rgba(0, 0, 0, .3); transition: transform .08s, box-shadow .08s, opacity .15s; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.big { width: 100%; padding: 14px; font-size: 17px; }
button.mini { padding: 3px 10px; font-size: 12px; border-radius: 99px; }

.screen { max-width: 520px; margin: 0 auto; padding: 16px; }
.field { display: block; margin-bottom: 12px; font-weight: 600; }
.field input { margin-top: 6px; font-weight: normal; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row > * { flex: 1; }
.row.small button { font-size: 13px; padding: 8px; }
.or { text-align: center; color: var(--muted); margin: 20px 0 4px; font-size: 13px; }

.rules { margin-top: 24px; background: rgba(255, 255, 255, .06); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.rules summary { font-weight: 700; cursor: pointer; }
.rules li { margin: 7px 0; font-size: 14px; line-height: 1.45; }

/* ── Phòng chờ ── */
.roomcode { text-align: center; color: var(--muted); margin-top: 8px; }
.roomcode b { display: block; font-size: 56px; letter-spacing: .15em; color: var(--accent); }
.chips-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { border-radius: 99px; padding: 8px 16px; min-width: 64px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip:disabled.on { opacity: 1; }
.money-now { flex-basis: 100%; display: flex; gap: 8px; align-items: center; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  border-radius: 16px; padding: 12px; min-height: 118px;
  background: rgba(255, 255, 255, .06); border: 2px solid color-mix(in srgb, var(--c) 70%, transparent);
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
}
.seat .color { font-weight: 800; color: var(--c); display: flex; align-items: center; gap: 6px; font-size: 13px; }
.seat .color::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.seat .who { font-size: 16px; font-weight: 700; }
.seat .who.empty { color: var(--muted); font-weight: 500; }
.seat .money { font-size: 13px; color: var(--muted); }
.seat .money small { font-weight: 700; }
.seat.mine { background: color-mix(in srgb, var(--c) 18%, transparent); }
.seat button { padding: 6px 10px; font-size: 13px; }
.seat .btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* ── Màn chơi: canvas 3D toàn màn hình, HUD đè lên ── */
#game { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 35%, #2a1d14 0, #120c08 75%); }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#hudTop {
  position: absolute; top: 0; left: 0; right: 0;
  padding: max(8px, env(safe-area-inset-top)) 100px 4px 10px;
  pointer-events: none;
}
#turnLine {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, .55); border-radius: 999px; padding: 6px 14px;
  font-weight: 800; font-size: 16px; backdrop-filter: blur(4px);
}
#turnLine .dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255, 255, 255, .5); }
#topLine { margin: 5px 0 0 4px; font-size: 13px; color: #e8e2cf; text-shadow: 0 1px 2px #000; }
.timer { height: 5px; margin-top: 6px; max-width: 260px; background: rgba(255, 255, 255, .15); border-radius: 99px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width .25s linear; }
.timer.low i { background: var(--red); }

.corner-btns { position: absolute; top: max(8px, env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; background: rgba(0, 0, 0, .5); }
.icon-btn.off { opacity: .5; }

/* Bảng tên người chơi */
#seatChips { position: absolute; inset: 0; pointer-events: none; }
.seatchip {
  position: absolute; display: flex; align-items: center; gap: 7px;
  background: rgba(10, 18, 14, .78); border: 2px solid rgba(255, 255, 255, .12);
  border-radius: 14px; padding: 4px 9px 4px 4px; max-width: 46vw;
  backdrop-filter: blur(4px); transition: border-color .2s, box-shadow .2s;
}
.seatchip .ava {
  flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--c); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.seatchip .info { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.seatchip .nm { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seatchip .mn { font-size: 12px; color: #d9d2bd; white-space: nowrap; }
.seatchip .cnt.warn { color: #ff8a65; animation: blink 1s infinite; }
.seatchip .tag {
  position: absolute; top: -9px; right: -6px; font-size: 11px; padding: 1px 7px; border-radius: 99px;
  background: #37474f; color: #fff; white-space: nowrap; box-shadow: 0 2px 4px rgba(0, 0, 0, .4);
}
.seatchip .tag.good { background: var(--accent); color: var(--accent-ink); }
.seatchip .tag.bad { background: var(--red); color: #fff; }
.seatchip.cur { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(242, 193, 78, .35), 0 0 18px rgba(242, 193, 78, .4); }
.seatchip.off { opacity: .55; }
.seatchip .ring { display: none; }
@keyframes blink { 50% { opacity: .35; } }

.moneyfx {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  font-weight: 900; font-size: 18px; text-shadow: 0 2px 4px #000; white-space: nowrap;
  animation: rise 1.6s ease-out forwards;
}
.moneyfx.up { color: #9cff8f; }
.moneyfx.down { color: #ff8a80; }
@keyframes rise { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -46px); } }

/* Nút đánh / bỏ lượt, nằm ngay trên bài */
#actionBar {
  position: absolute; left: 0; right: 0; bottom: 130px;
  display: flex; gap: 8px; justify-content: center; padding: 0 10px;
  pointer-events: none;
}
#actionBar button { pointer-events: auto; padding: 10px 16px; border-radius: 999px; font-size: 15px; }
#actionBar .ghost { background: rgba(0, 0, 0, .5); }
#actionBar #passBtn { background: rgba(0, 0, 0, .55); }
#actionBar #playBtn { min-width: 120px; max-width: 58vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#actionBar #playBtn.pulse { animation: nudge 1.4s ease-in-out infinite; }
#actionBar.idle #passBtn, #actionBar.idle #playBtn { visibility: hidden; }
#actionBar.dealing { visibility: hidden; }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* Hiệu ứng chữ lớn: CHẶT!, TỚI TRẮNG!, CHÁY! */
.bigfx {
  position: absolute; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none;
  font-size: min(18vw, 110px); font-weight: 900; letter-spacing: .04em; font-family: Georgia, serif;
  -webkit-text-stroke: 3px #000; text-shadow: 0 6px 0 rgba(0, 0, 0, .5);
}
.bigfx.red { color: #ff5252; }
.bigfx.gold { color: #ffd54f; }
.bigfx.go { animation: slam 1.4s ease-out forwards; }
@keyframes slam {
  0% { transform: scale(2.6) rotate(-8deg); opacity: 0; }
  15% { transform: scale(1) rotate(-4deg); opacity: 1; }
  75% { transform: scale(1.08) rotate(-4deg); opacity: 1; }
  100% { transform: scale(1.2) rotate(-4deg); opacity: 0; }
}

/* Nhật ký */
.sheet {
  position: absolute; right: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 48px);
  width: min(calc(100vw - 20px), 380px); max-height: 60vh; display: flex; flex-direction: column;
  background: rgba(12, 20, 16, .95); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px;
  z-index: 20;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head .icon-btn { width: 32px; height: 32px; font-size: 14px; }
#log { list-style: none; padding: 0; margin: 6px 0; overflow: auto; font-size: 13px; }
#log li { padding: 4px 0; border-bottom: 1px solid var(--line); }

/* Kết quả ván */
.result { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); z-index: 15; padding: 12px; }
.result:has(.floating) { background: none; pointer-events: none; }
.result .floating { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 12px); right: 12px; pointer-events: auto; border-radius: 99px; }
.result .box {
  background: #f9f6ee; color: var(--ink); border-radius: 20px; padding: 18px 18px 14px;
  width: min(94vw, 420px); max-height: 88vh; overflow: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); animation: pop .35s ease-out;
}
.result h3 { margin: 0 0 10px; font-size: 21px; text-align: center; }
.result h3 small { display: block; font-size: 14px; color: #7a6a3a; font-weight: 600; }
.result .res { width: 100%; border-collapse: collapse; }
.result .res td { padding: 7px 4px; border-bottom: 1px solid #e6e0d0; font-size: 15px; }
.result .res td:first-child { font-weight: 800; width: 64px; }
.result .res td:nth-child(3) { text-align: right; }
.result .res td:last-child { text-align: right; width: 84px; }
.result .res tr.me td { background: #fff3cf; }
.result .up { color: #2e7d32; }
.result .down { color: #c62828; }
.result .muted { color: #7d867f; }
.result .pays { margin-top: 8px; font-size: 13px; }
.result .pays summary { cursor: pointer; color: #556; font-weight: 700; }
.result .pays ul { margin: 6px 0 0; padding-left: 18px; }
.result button { background: #fff; color: var(--ink); border-color: #d9d3c3; box-shadow: 0 3px 0 rgba(0, 0, 0, .12); }
.result button.primary { background: #2e7d32; border-color: #2e7d32; color: #fff; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: #e65100; color: #fff; text-align: center; padding: 6px; font-size: 14px;
}
.toast {
  position: fixed; left: 50%; top: 30%; transform: translateX(-50%); z-index: 60;
  background: rgba(20, 24, 22, .95); color: #fff; padding: 10px 16px; border-radius: 12px;
  max-width: calc(100vw - 32px); font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  border: 1px solid var(--line);
}

/* Điện thoại xoay ngang: thu gọn chữ phía trên */
@media (orientation: landscape) and (max-height: 500px) {
  #topLine { display: none; }
  #turnLine { font-size: 14px; padding: 4px 12px; }
  .seatchip .ava { width: 26px; height: 26px; font-size: 13px; }
  #actionBar button { padding: 7px 14px; font-size: 14px; }
  #actionBar.side {
    left: auto; right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom));
    flex-direction: column-reverse; padding: 0; width: 132px;
  }
  #actionBar.side #playBtn { min-width: 0; max-width: none; }
  .seatchip { max-width: 30vw; }
}
