:root {
  --dealer-image: none;
  --scene-photo: none;
  --felt: #07544f;
  --felt-dark: #043632;
  --gold: #d6a646;
  --gold-bright: #ffd979;
  --red: #d44837;
  --ink: #10141b;
  --panel: rgba(6, 11, 18, 0.72);
  --panel-strong: rgba(8, 13, 22, 0.9);
  --line: rgba(255, 255, 255, 0.18);
  --text: #f6f1e6;
  --muted: rgba(246, 241, 230, 0.72);
  --green: #50d77b;
  --danger: #ff786d;
  --table-w: min(78vw, 1080px);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 196, 107, 0.28), transparent 30%),
    linear-gradient(180deg, #1d1412 0%, #0c0f14 52%, #070a0e 100%);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app {
  position: relative;
  min-height: 100vh;
}

.topbar {
  position: fixed;
  z-index: 20;
  inset: 0 0 auto;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(5, 7, 11, 0.72), rgba(5, 7, 11, 0));
  letter-spacing: 0;
}

.table-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
}

.table-title strong {
  color: var(--gold-bright);
}

.game-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  height: 30px;
  min-width: 48px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  backdrop-filter: blur(10px);
}

.icon-button.is-muted {
  color: rgba(255, 255, 255, 0.58);
}

.icon-button.is-active {
  color: #171008;
  background: linear-gradient(180deg, #f6d98f, #c98831);
}

.photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.scene {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.dealer-stage {
  position: absolute;
  inset: 0 0 auto;
  height: 48vh;
  min-height: 330px;
  overflow: hidden;
  background:
    var(--scene-photo),
    linear-gradient(90deg, rgba(0, 0, 0, 0.48), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.48)),
    radial-gradient(circle at 50% 32%, rgba(255, 200, 122, 0.26), transparent 26%);
  background-size: cover, auto, auto;
  background-position: center, center, center;
  background-repeat: no-repeat;
}

.light-wall {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
  padding: 0 70px;
  opacity: 0.92;
  transform: perspective(760px) rotateX(3deg);
}

.light-wall span {
  display: block;
  height: 100%;
  background:
    linear-gradient(180deg, transparent 0 10%, rgba(255, 210, 128, 0.8) 10% 17%, transparent 17% 24%, rgba(255, 157, 67, 0.52) 24% 49%, transparent 49% 57%, rgba(255, 217, 139, 0.86) 57% 68%, transparent 68%),
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  filter: blur(0.2px) drop-shadow(0 0 13px rgba(255, 176, 66, 0.8));
  transform: translateY(calc(var(--i, 1) * -2px));
}

.light-wall span:nth-child(2n) {
  margin-top: 28px;
}

.light-wall span:nth-child(3n) {
  margin-top: -20px;
}

.dealer-avatar {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(30vw, 320px);
  height: min(47vh, 500px);
  transform: translateX(-50%);
  animation: dealerIdle 4.8s ease-in-out infinite;
  overflow: visible;
}

.dealer-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  object-fit: contain;
  object-position: center center;
  filter: drop-shadow(0 20px 36px rgba(0, 0, 0, 0.58));
  opacity: 0;
  transition: opacity 180ms ease;
  background: transparent;
}

.dealer-avatar.has-video .idle-video {
  opacity: 1;
}

.dealer-avatar.has-video.is-speaking .idle-video {
  opacity: 0;
}

.dealer-avatar.has-video.is-speaking .talk-video {
  opacity: 1;
}

.dealer-avatar.has-video .dealer-photo,
.dealer-avatar.has-video .mouth {
  opacity: 0;
}

.dealer-photo {
  position: absolute;
  inset: 0;
  border-radius: 46% 46% 18px 18px;
  background-image:
    var(--dealer-image),
    radial-gradient(ellipse at 50% 30%, #f5d2b8 0 12%, transparent 13%),
    radial-gradient(ellipse at 50% 23%, #3b1519 0 21%, transparent 22%),
    radial-gradient(ellipse at 50% 82%, #d8ad71 0 42%, transparent 43%),
    linear-gradient(180deg, transparent 0 54%, #111 55% 100%);
  background-position: center bottom, center, center, center, center;
  background-repeat: no-repeat;
  background-size: cover, 58% 58%, 74% 54%, 86% 62%, cover;
  filter: drop-shadow(0 20px 36px rgba(0, 0, 0, 0.58));
  transition: opacity 180ms ease;
}

.dealer-photo::before {
  content: "";
  position: absolute;
  inset: -18px -30px auto;
  height: 65%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 218, 141, 0.24), transparent 67%);
  z-index: -1;
}

.dealer-shadow {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -18px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.36);
  filter: blur(10px);
}

.mouth {
  position: absolute;
  left: 50%;
  top: 31%;
  width: 22px;
  height: 5px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(86, 30, 31, 0.84);
  opacity: 0;
}

.dealer-avatar.is-speaking .mouth {
  opacity: 1;
  animation: mouthTalk 0.18s steps(2, end) infinite;
}

.dealer-avatar.has-video.is-speaking .mouth {
  opacity: 0;
  animation: none;
}

.dealer-caption {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(620px, 58vw);
  padding: 12px 16px 13px;
  border: 1px solid rgba(255, 218, 139, 0.34);
  border-radius: 8px;
  background: rgba(5, 8, 12, 0.52);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.app.has-photo .dealer-stage {
  height: 100vh;
  min-height: 100vh;
}

.app.has-photo .dealer-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.1), transparent 36%, rgba(0, 0, 0, 0.5)),
    radial-gradient(circle at 50% 43%, transparent 0 30%, rgba(0, 0, 0, 0.28) 76%);
  pointer-events: none;
}

.app.has-photo .light-wall,
.app.has-photo .dealer-avatar {
  display: none;
}

.app.has-photo .dealer-caption {
  z-index: 5;
  left: 22px;
  bottom: 23vh;
  transform: none;
  width: min(520px, 42vw);
}

.dealer-caption span {
  display: block;
  margin-bottom: 3px;
  color: var(--gold-bright);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.dealer-caption p {
  margin: 0;
  min-height: 24px;
  font-size: clamp(14px, 1.4vw, 18px);
}

.table-shell {
  position: absolute;
  left: 50%;
  bottom: -4vh;
  width: var(--table-w);
  height: min(56vh, 600px);
  transform: translateX(-50%);
  perspective: 980px;
}

.felt-table {
  position: absolute;
  inset: 0;
  border: clamp(16px, 2.2vw, 30px) solid #b97926;
  border-bottom-width: clamp(22px, 3vw, 42px);
  border-radius: 50% 50% 12% 12% / 26% 26% 16% 16%;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(255, 255, 255, 0.11), transparent 22%),
    radial-gradient(ellipse at 50% 78%, rgba(0, 0, 0, 0.24), transparent 52%),
    linear-gradient(180deg, #0b6b64, var(--felt) 52%, var(--felt-dark));
  box-shadow:
    inset 0 0 0 6px rgba(0, 0, 0, 0.22),
    inset 0 -34px 68px rgba(0, 0, 0, 0.27),
    0 40px 80px rgba(0, 0, 0, 0.65);
  transform: rotateX(48deg);
  transform-origin: center bottom;
}

.app.has-photo .table-shell {
  left: 0;
  bottom: 0;
  width: 100vw;
  height: 56vh;
  transform: none;
  perspective: none;
  pointer-events: none;
}

.app.has-photo .felt-table {
  inset: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  transform: none;
  pointer-events: none;
}

.app.has-photo .felt-table::after,
.app.has-photo .logo-mark,
.app.has-photo .qualify-mark {
  display: none;
}

.app.has-photo .zone {
  pointer-events: auto;
}

.app.has-photo .dealer-zone {
  top: 12%;
}

.app.has-photo .board-zone {
  top: 40%;
}

.app.has-photo .player-zone {
  top: 67%;
}

.app.has-photo .side-tray {
  display: none;
}

.felt-table::after {
  content: "";
  position: absolute;
  inset: 4% 3%;
  border-radius: inherit;
  border: 2px solid rgba(255, 220, 126, 0.28);
  pointer-events: none;
}

.logo-mark {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  color: rgba(255, 218, 126, 0.68);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 5vw, 70px);
  font-weight: 700;
  line-height: 0.78;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.32);
  pointer-events: none;
}

.logo-mark strong {
  color: rgba(220, 62, 48, 0.82);
  font-size: 0.62em;
}

.qualify-mark {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 58%;
  transform: translate(-50%, -50%);
  padding: 7px 16px;
  border-top: 2px solid rgba(255, 224, 130, 0.6);
  border-bottom: 2px solid rgba(255, 224, 130, 0.6);
  border-radius: 50%;
  color: rgba(255, 233, 145, 0.82);
  font-size: clamp(12px, 1.7vw, 24px);
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}

.zone {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  min-width: 260px;
}

.dealer-zone {
  top: 5%;
}

.board-zone {
  top: 35%;
}

.player-zone {
  top: 58%;
}

.zone-label {
  margin-bottom: 6px;
  color: rgba(255, 233, 166, 0.84);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-align: center;
  text-transform: uppercase;
}

.cards-row {
  display: flex;
  justify-content: center;
  gap: clamp(6px, 0.8vw, 12px);
  min-height: clamp(58px, 8.3vw, 98px);
}

.card {
  width: clamp(42px, 5.6vw, 70px);
  height: clamp(58px, 7.7vw, 98px);
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background:
    linear-gradient(145deg, #fff 0%, #e8e4da 100%);
  color: #191b20;
  box-shadow:
    0 8px 16px rgba(0, 0, 0, 0.38),
    inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transform: translateY(0);
  transition: transform 220ms ease, box-shadow 220ms ease, opacity 220ms ease;
}

.card.is-red {
  color: #b42322;
}

.card.back {
  background:
    radial-gradient(circle at center, rgba(255, 226, 148, 0.38), transparent 37%),
    repeating-linear-gradient(45deg, #50210f 0 8px, #813b17 8px 16px);
}

.card.best {
  transform: translateY(-8px);
  box-shadow:
    0 0 0 3px rgba(255, 222, 102, 0.78),
    0 12px 22px rgba(0, 0, 0, 0.42);
}

.card.dealt {
  animation: cardDeal 360ms cubic-bezier(0.2, 0.82, 0.22, 1) both;
}

.rank {
  font-size: clamp(18px, 2.4vw, 30px);
  font-weight: 900;
}

.suit {
  position: absolute;
  right: 7px;
  bottom: 5px;
  font-size: clamp(10px, 1.2vw, 15px);
  font-weight: 800;
}

.corner-rank {
  position: absolute;
  left: 7px;
  top: 4px;
  font-size: clamp(10px, 1.2vw, 15px);
  font-weight: 900;
}

.hand-readout {
  margin-top: 4px;
  min-height: 17px;
  color: #fff8dc;
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 750;
  text-align: center;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
}

.side-tray {
  position: absolute;
  z-index: 2;
  top: 18%;
  display: grid;
  place-items: center;
  gap: 7px;
  color: rgba(255, 238, 197, 0.66);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.left-tray {
  left: 8%;
}

.right-tray {
  right: 8%;
}

.card-shoe,
.discard-rack {
  width: 82px;
  height: 48px;
  border-radius: 6px;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.22), transparent 36%),
    linear-gradient(160deg, #3a2215, #0b0d10);
  box-shadow: 0 18px 26px rgba(0, 0, 0, 0.42);
}

.discard-rack {
  width: 96px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.3), transparent 42%),
    rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(5px);
}

.hud {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: 18px;
  width: min(360px, calc(100vw - 36px));
  display: grid;
  gap: 10px;
}

.bet-panel,
.action-panel,
.result-panel,
.log-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

.bet-panel {
  padding: 12px;
  display: grid;
  gap: 9px;
}

.balance-row,
.input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.balance-row span,
.input-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.balance-row strong {
  color: var(--gold-bright);
  font-size: 18px;
}

.input-row input {
  width: 118px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.34);
  color: #fff;
  padding: 0 10px;
  text-align: right;
}

.chip-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.chip {
  height: 34px;
  border-radius: 999px;
  background:
    radial-gradient(circle, #f7f0e2 0 29%, transparent 30%),
    conic-gradient(#a41516 0 20deg, #fff 20deg 36deg, #a41516 36deg 72deg, #fff 72deg 90deg, #a41516 90deg 360deg);
  color: #16110f;
  font-weight: 950;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.08), 0 6px 14px rgba(0, 0, 0, 0.26);
}

.action-panel {
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-action,
.secondary-action {
  height: 42px;
  border-radius: 7px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.primary-action {
  background: linear-gradient(180deg, #f6c86b, #a96b1c);
  color: #171008;
}

.call-action {
  background: linear-gradient(180deg, #65e78b, #178842);
  color: #041008;
}

.secondary-action {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

.result-panel,
.log-panel {
  padding: 11px 12px;
}

.panel-title {
  margin-bottom: 8px;
  color: var(--gold-bright);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#payoutRows {
  margin: 0;
  display: grid;
  gap: 6px;
}

#payoutRows div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

#payoutRows dt {
  margin: 0;
}

#payoutRows dd {
  margin: 0;
  color: #fff;
  font-weight: 850;
}

#payoutRows .positive dd {
  color: var(--green);
}

#payoutRows .negative dd {
  color: var(--danger);
}

.log-panel {
  max-height: 158px;
  overflow: auto;
}

#handLog {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
}

#handLog li + li {
  margin-top: 5px;
}

@keyframes dealerIdle {
  0%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(5px);
  }
}

@keyframes mouthTalk {
  0% {
    height: 4px;
  }
  100% {
    height: 14px;
  }
}

@keyframes cardDeal {
  0% {
    opacity: 0;
    transform: translateY(-22px) scale(0.82) rotate(-4deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .scene {
    min-height: 100vh;
    height: 100svh;
  }

  .dealer-caption {
    width: calc(100vw - 32px);
    bottom: 92px;
    padding: 10px 12px;
  }

  .dealer-caption p {
    font-size: 13px;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .hud {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    grid-template-columns: 1fr;
  }

  .table-shell {
    width: 126vw;
    height: 42vh;
    bottom: 25vh;
  }

  .dealer-avatar {
    width: min(46vw, 220px);
    height: min(41vh, 390px);
    bottom: 38px;
  }

  .side-tray {
    display: none;
  }

  .result-panel,
  .log-panel {
    display: none;
  }

  .app.has-photo .dealer-caption {
    left: 16px;
    right: 16px;
    top: 31vh;
    bottom: auto;
    width: auto;
  }

  .app.has-photo .table-shell {
    width: 100vw;
    height: 47vh;
    bottom: 24vh;
  }

  .app.has-photo .dealer-zone {
    top: 11%;
  }

  .app.has-photo .board-zone {
    top: 42%;
  }

  .app.has-photo .player-zone {
    top: 70%;
  }
}

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