*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #050307;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* MAIN PORTRAIT STAGE */
.bj-stage {
  --ss: 400px;

  position: relative;
  width: min(100vw, calc(100dvh * 768 / 1365));
  aspect-ratio: 768 / 1365;
  overflow: hidden;
  background: #050307;
  isolation: isolate;
}

/* BACKGROUND / TABLE IMAGE */
.bj-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
  z-index: 0;
}

/* LOBBY HOTSPOT */
.bj-lobby-hotspot {
  position: absolute;
  left: 3.2%;
  top: 2.1%;
  width: 10%;
  height: 5.7%;
  border-radius: 50%;
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
}

/* CARD AREAS */
.bj-dealer-area,
.bj-player-area {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
}

.bj-dealer-area {
  top: 24.6%;
  width: 34%;
  height: 10.8%;
}

.bj-player-area {
  top: 56.7%;
  width: 38%;
  height: 12.2%;
}

.bj-card-row {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--ss) * 0.016);
}

/* HIDE TOTAL BADGES FOR NOW */
.bj-hand-total {
  display: none !important;
}

/* CARDS */
.bj-card {
  position: relative;
  width: calc(var(--ss) * 0.122);
  aspect-ratio: 2.5 / 3.5;
  border-radius: calc(var(--ss) * 0.014);
  overflow: hidden;
  box-shadow:
    0 5px 12px rgba(0, 0, 0, 0.62),
    inset 0 0 0 1px rgba(255, 240, 180, 0.38);
  animation: bjDealCard 0.22s ease-out both;
}

@keyframes bjDealCard {
  from {
    transform: translateY(-10px) scale(0.96);
    opacity: 0;
  }

  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* CARD BACK */
.card-back {
  background:
    radial-gradient(circle at center, rgba(96, 28, 113, 0.78), transparent 58%),
    linear-gradient(145deg, #120717, #3a1044 48%, #09040d);
  border: 2px solid #d8b25e;
}

.card-back::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 1px solid rgba(216, 178, 94, 0.9);
  border-radius: calc(var(--ss) * 0.011);
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 1px solid rgba(216, 178, 94, 0.38);
  border-radius: calc(var(--ss) * 0.009);
}

.card-back-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62%;
  height: 62%;
  object-fit: contain;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
  user-select: none;
  filter:
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.9))
    drop-shadow(0 0 7px rgba(216, 178, 94, 0.45));
}

/* FACE-UP CARD */
.card-face {
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.85), transparent 35%),
    linear-gradient(145deg, #fff7e7, #d8c6a3);
  border: 2px solid #d8b25e;
  color: #111;
}

.card-face.red {
  color: #a50f1f;
}

.corner {
  position: absolute;
  display: grid;
  line-height: 0.9;
  text-align: center;
  font-weight: 900;
  font-family: Georgia, "Times New Roman", serif;
}

.corner.top {
  top: 7%;
  left: 9%;
}

.corner.bottom {
  right: 9%;
  bottom: 7%;
  transform: rotate(180deg);
}

.rank {
  font-size: calc(var(--ss) * 0.033);
}

.suit {
  font-size: calc(var(--ss) * 0.031);
}

.suit-center,
.pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--ss) * 0.085);
  opacity: 0.96;
}

/* MAIN BET CHIP */
.main-bet-chip-layer {
  position: absolute;
  left: 50%;
  top: 72.8%;
  width: calc(var(--ss) * 0.086);
  height: calc(var(--ss) * 0.086);
  transform: translate(-50%, -50%);
  z-index: 12;
  pointer-events: none;
}

.main-bet-chip-layer img,
.main-bet-chip {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.7));
}

.main-bet-chip-custom {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 35% 28%, #fff0ad, #e1b94e 56%, #7a5213);
  color: #160e05;
  font-size: calc(var(--ss) * 0.024);
  font-weight: 900;
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.65),
    inset 0 0 0 2px rgba(255, 255, 255, 0.55);
}

/* MESSAGE BANNER */
.bj-message {
  position: absolute;
  left: 50%;
  top: 76.3%;
  transform: translateX(-50%);
  width: 74%;
  min-height: calc(var(--ss) * 0.058);
  padding: calc(var(--ss) * 0.01) calc(var(--ss) * 0.024);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(216, 178, 94, 0.68);
  border-radius: calc(var(--ss) * 0.021);
  background:
    radial-gradient(circle at 50% 0%, rgba(122, 35, 122, 0.62), transparent 60%),
    rgba(10, 4, 13, 0.88);
  color: #f2d881;
  text-align: center;
  font-size: calc(var(--ss) * 0.028);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow:
    0 2px 5px rgba(0, 0, 0, 0.85),
    0 0 9px rgba(216, 178, 94, 0.32);
  box-shadow:
    0 0 14px rgba(216, 178, 94, 0.18),
    inset 0 0 0 1px rgba(255, 240, 180, 0.16);
}

.bj-message.good {
  color: #42e985;
  border-color: rgba(66, 233, 133, 0.42);
}

.bj-message.bad {
  color: #ff6666;
  border-color: rgba(255, 102, 102, 0.42);
}

.bj-message.warn {
  color: #f2d881;
}

/* BOTTOM UI */
.bj-bottom-ui {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24.8%;
  z-index: 20;
  pointer-events: none;
}

/* INFO PANELS */
.bj-info-panels {
  position: absolute;
  left: 4.2%;
  right: 4.2%;
  top: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.8%;
  pointer-events: none;
}

.bj-info-panel {
  position: relative;
  height: calc(var(--ss) * 0.138);
}

.bj-info-panel img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
}

.bj-panel-value {
  position: absolute;
  left: 50%;
  top: 68%;
  transform: translate(-50%, -50%);
  z-index: 2;
  color: #f5ead4;
  font-size: calc(var(--ss) * 0.028);
  font-weight: 900;
  letter-spacing: -0.35px;
  white-space: nowrap;
  text-shadow:
    0 2px 4px rgba(0, 0, 0, 0.95),
    0 0 7px rgba(216, 178, 94, 0.25);
}

/* CHIP RACK */
.bj-chip-rack-wrap {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 31.2%;
  height: calc(var(--ss) * 0.128);
  pointer-events: auto;
}

.bj-chip-rack-bg {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--ss) * 0.026);
  background:
    linear-gradient(180deg, #181114, #050406),
    radial-gradient(circle at 50% 0%, rgba(122, 35, 122, 0.55), transparent 68%);
  border: 2px solid rgba(216, 178, 94, 0.62);
  box-shadow:
    0 0 12px rgba(216, 178, 94, 0.22),
    inset 0 0 0 2px rgba(255, 240, 180, 0.08),
    inset 0 0 18px rgba(0, 0, 0, 0.85);
}

.bj-chip-btn {
  position: absolute;
  top: 50%;
  width: 15%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bj-chip-btn:nth-of-type(1) { left: 14.7%; }
.bj-chip-btn:nth-of-type(2) { left: 32.3%; }
.bj-chip-btn:nth-of-type(3) { left: 50%; }
.bj-chip-btn:nth-of-type(4) { left: 67.7%; }
.bj-chip-btn:nth-of-type(5) { left: 85.3%; }

.bj-chip-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.7));
}

.bj-chip-btn.selected,
.bj-chip-btn.active {
  box-shadow:
    0 0 0 2px rgba(255, 220, 98, 0.95),
    0 0 16px rgba(255, 220, 98, 0.7);
}

/* CODED ACTION BUTTONS */
.bj-controls {
  position: absolute;
  left: 5.8%;
  right: 5.8%;
  top: 61.2%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: calc(var(--ss) * 0.01);
  pointer-events: auto;
}

.bj-control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--ss) * 0.02);
}

.bj-control-stack {
  display: flex;
  flex-direction: column;
  gap: calc(var(--ss) * 0.01);
}

.bj-small-row {
  padding: 0 7%;
}

.bj-action-btn {
  position: relative;
  height: calc(var(--ss) * 0.07);
  border: 0;
  padding: 0;
  background-color: transparent;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  color: #f3d681;
  font-family: Georgia, "Times New Roman", serif;
  font-size: calc(var(--ss) * 0.033);
  font-weight: 900;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  text-shadow:
    0 2px 4px rgba(0, 0, 0, 0.95),
    0 0 8px rgba(216, 178, 94, 0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bj-action-btn span {
  position: relative;
  z-index: 2;
}

.bj-btn-primary.bj-btn-left {
  background-image: url("assets/bj-btn-primary-left.png");
}

.bj-btn-primary.bj-btn-right {
  background-image: url("assets/bj-btn-primary-right.png");
}

.bj-btn-secondary.bj-btn-left {
  background-image: url("assets/bj-btn-secondary-left.png");
}

.bj-btn-secondary.bj-btn-right {
  background-image: url("assets/bj-btn-secondary-right.png");
}

.bj-small-row .bj-action-btn {
  height: calc(var(--ss) * 0.05);
  font-size: calc(var(--ss) * 0.023);
}

.bj-action-btn:active {
  transform: scale(0.98);
  filter:
    drop-shadow(0 0 8px rgba(255, 220, 98, 0.6))
    brightness(1.08);
}

.bj-action-btn:disabled {
  opacity: 0.36;
  filter: grayscale(0.75);
  cursor: default;
}

/* FOOTER */
.bj-footer {
  position: absolute;
  left: 50%;
  bottom: 0.5%;
  width: 52%;
  transform: translateX(-50%);
  user-select: none;
  pointer-events: none;
}

/* TOAST */
.bj-toast {
  position: absolute;
  left: 50%;
  bottom: 26%;
  transform: translate(-50%, 8px);
  max-width: 86%;
  z-index: 60;
  padding: calc(var(--ss) * 0.016) calc(var(--ss) * 0.038);
  border-radius: 999px;
  background: rgba(14, 7, 20, 0.9);
  color: #f6efdd;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: calc(var(--ss) * 0.03);
  font-weight: 700;
  text-align: center;
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(238, 205, 120, 0.45);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

.bj-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* HIDDEN UTILITY DATA */
.bj-hidden-data {
  display: none !important;
}

.hidden {
  display: none !important;
}

/* DEBUG MODE:
   Add class="debug" to body to line things up.
*/
body.debug .bj-lobby-hotspot,
body.debug .bj-chip-btn {
  background: rgba(255, 0, 120, 0.28);
  outline: 1px solid #ff2d8e;
}

body.debug .bj-dealer-area,
body.debug .bj-player-area,
body.debug .main-bet-chip-layer,
body.debug .bj-message,
body.debug .bj-bottom-ui {
  outline: 1px dashed #00e5ff;
}

/* ACCESSIBILITY */
.bj-lobby-hotspot:focus-visible,
.bj-chip-btn:focus-visible,
.bj-action-btn:focus-visible {
  outline: 2px solid #ffd24a;
  outline-offset: -2px;
}

/* SMALL PHONE TUNING */
@media (max-height: 720px) {
  .bj-card {
    width: calc(var(--ss) * 0.112);
  }

  .bj-message {
    top: 76%;
    min-height: calc(var(--ss) * 0.052);
    font-size: calc(var(--ss) * 0.025);
  }

  .bj-action-btn {
    height: calc(var(--ss) * 0.062);
    font-size: calc(var(--ss) * 0.03);
  }

  .bj-small-row .bj-action-btn {
    height: calc(var(--ss) * 0.044);
    font-size: calc(var(--ss) * 0.021);
  }
}

/* REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
  .bj-card {
    animation: none !important;
  }

  .bj-toast {
    transition: none !important;
  }
}

/* =========================================
   POSITION + STACKED BET CHIP PATCH
   ========================================= */

/* move dealer cards up */
.bj-dealer-area {
  top: 22.2%;
  width: 34%;
  height: 10.8%;
}

/* move player cards up */
.bj-player-area {
  top: 52.8%;
  width: 38%;
  height: 12.2%;
}

/* make the bet chip area larger and move it up into the MAIN BET circle */
.main-bet-chip-layer {
  position: absolute;
  left: 50%;
  top: 69.7%;
  width: calc(var(--ss) * 0.19);
  height: calc(var(--ss) * 0.14);
  transform: translate(-50%, -50%);
  z-index: 12;
  pointer-events: none;
}

/* stacked chip layout */
.bet-chip-stack {
  position: relative;
  width: 100%;
  height: 100%;
}

.bet-stack-item {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--ss) * 0.09);
  height: calc(var(--ss) * 0.09);
  transform: translate(
    calc(-50% + var(--x, 0px)),
    calc(-50% + var(--y, 0px))
  );
  z-index: var(--z, 1);
}

.bet-stack-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.7));
}

.bet-stack-count {
  position: absolute;
  right: -8%;
  bottom: -6%;
  min-width: calc(var(--ss) * 0.04);
  height: calc(var(--ss) * 0.04);
  padding: 0 calc(var(--ss) * 0.01);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 8, 16, 0.92);
  border: 1px solid rgba(255, 220, 98, 0.8);
  color: #f4d883;
  font-size: calc(var(--ss) * 0.018);
  font-weight: 900;
  line-height: 1;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.65),
    inset 0 0 0 1px rgba(255, 240, 180, 0.15);
}

/* optional: tighten message bar so it doesn't fight the circle */
.bj-message {
  top: 76%;
}