:root {
  --navbar-height: 56px;
  --bg-deep: rgb(7 11 35);
  --bg-base: rgb(12 16 43);
  --bg-elevated: rgb(18 23 49);
  --bg-panel: rgb(24 30 60);
  --bg-panel-hover: rgb(31 37 70);
  --border-subtle: rgba(52, 60, 100, 0.45);
  --border-strong: rgba(52, 60, 100, 0.65);
  --text-primary: rgb(255 255 255);
  --text-secondary: rgb(164 170 198);
  --text-muted: rgb(118 127 170);
  --accent: rgb(43 99 244);
  --accent-soft: rgba(43, 99, 244, 0.18);
  --success: rgb(32 208 149);
  --danger: rgb(232 48 94);
  --card-face: rgb(248 250 252);
  --card-radius: 8px;
  --card-aspect: 409 / 610;
  --card-w: 82px;
  --card-h: calc(var(--card-w) / (409 / 610));
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --font: TT-Interphases-Pro, system-ui, -apple-system, sans-serif;
}

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

#game-root {
  font-family: var(--font);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.duel-page .btn {
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition:
    background 0.25s var(--ease-out),
    transform 0.2s var(--ease-out),
    box-shadow 0.25s var(--ease-out),
    opacity 0.25s var(--ease-out);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn--primary {
  background: rgb(43 99 244);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: rgb(55 112 248);
}

.btn--ghost {
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--bg-panel-hover);
  border-color: rgba(124, 156, 255, 0.35);
}

.btn--success {
  background: #5eead4;
  color: #0f172a;
}

#game-root .game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Duel.com blackjack: centered table, actions row, bet panel below */
.duel-bj-page {
  width: 100%;
}

.duel-bj-stage .table-wrap {
  max-width: 100%;
}

.duel-bj-actions.action-dock {
  position: relative;
  z-index: 5;
  max-width: 640px;
  justify-content: center;
  min-height: 48px;
  gap: 10px;
}

.bj-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 108px;
  height: 48px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid rgba(90, 105, 160, 0.55);
  background: rgb(24 30 60);
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.bj-action:hover:not(:disabled) {
  background: rgb(31 37 70);
  border-color: rgba(140, 155, 210, 0.7);
}

.bj-action:active:not(:disabled) {
  transform: scale(0.98);
}

.bj-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bj-action--hit {
  background: rgb(43 99 244);
  border-color: transparent;
}

.bj-action--hit:hover:not(:disabled) {
  background: rgb(59 115 255);
  border-color: transparent;
}

.bj-action__icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
}

.bj-action__icon svg {
  width: 100%;
  height: 100%;
}

.bj-action[hidden] {
  display: none !important;
}

.duel-bj-actions__left,
.duel-bj-actions__right {
  min-height: 48px;
  gap: 12px;
}

.duel-action-btn__icon {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  opacity: 0.95;
}

.duel-action-btn__icon svg {
  width: 100%;
  height: 100%;
}

.duel-bj-actions .duel-action-btn {
  min-width: 0;
  gap: 8px;
}

.duel-bj-actions .duel-action-btn__label {
  font-size: inherit;
  letter-spacing: 0.01em;
}

.duel-bj-controls {
  width: 100%;
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid rgba(52, 60, 100, 0.45);
  gap: 32px;
}

.duel-bj-meta {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 8px;
}

.duel-bj-page .duel-bj-stage {
  margin-bottom: 4px;
}

.duel-bj-page .message-bar {
  margin-top: 12px;
  margin-bottom: 4px;
  max-width: 1040px;
}

.duel-bj-play-slot {
  min-height: 56px;
}

.duel-bj-play-slot .blackjack-bet-panel {
  width: 100%;
}

.duel-bj-play-slot .blackjack-bet-panel--hidden,
.duel-bj-play-slot .blackjack-bet-panel[hidden] {
  display: none !important;
  max-height: none;
  margin: 0;
  padding: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.duel-bj-play-slot #action-dock[hidden] {
  display: none !important;
}

.blackjack-bet-panel {
  transition:
    opacity 0.35s var(--ease-out),
    transform 0.35s var(--ease-out),
    max-height 0.4s var(--ease-out),
    margin 0.35s var(--ease-out),
    padding 0.35s var(--ease-out);
}

.blackjack-bet-panel--hidden,
.blackjack-bet-panel[hidden] {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  max-height: 0;
  overflow: hidden;
  margin: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border: none;
}

.table-wrap {
  width: 100%;
  max-width: 1040px;
  min-height: 420px;
  border-radius: 16px;
  border: 1px solid rgb(52 60 100);
  background: rgb(18 23 49);
  box-shadow: none;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
  position: relative;
  overflow: hidden;
  transition: filter 0.4s var(--ease-out);
}

.table-wrap--busy {
  /* stay clipped  -  flying cards use a viewport layer, not table overflow */
}

.table-wrap--busy::after {
  content: none;
}

.table-wrap::before {
  content: none;
}

.table-stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  flex: 1;
  justify-content: center;
  padding-top: 8px;
  padding-right: calc(var(--card-w) + 20px);
}

@media (max-width: 640px) {
  .table-stage {
    padding-right: 0;
    padding-top: 88px;
  }
}

/* Shoe / deck  -  face-down stack cards are dealt from */
.shoe-tower {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  width: var(--card-w);
  height: calc(var(--card-h) + 28px);
  pointer-events: none;
  overflow: hidden;
}

.shoe-tower__stack {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}

.shoe-tower__card {
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background-color: #0b1538;
  background-image: url("/assets/cards/tidebet-back.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(52, 60, 100, 0.55);
  transform: translateY(calc(var(--shoe-i, 0) * -3px));
  overflow: hidden;
  transition:
    transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.18s ease-out;
}

.shoe-tower__card--pull {
  transform: translateY(calc(var(--shoe-i, 0) * -3px - 14px)) scale(0.94);
  opacity: 0;
}


.table-rules {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
  position: relative;
  z-index: 1;
}

.hand-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  z-index: 1;
}

.hand-row__header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.hand-row__title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.hand-row__score {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 2ch;
  text-align: center;
}

.hand-row__bet {
  font-size: 12px;
  color: var(--text-secondary);
}

.cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 108px;
  align-items: center;
  justify-content: center;
  perspective: 900px;
}

/* Dealer: hole card + hits overlap ~50% of card width */
.cards--dealer {
  gap: 0;
  flex-wrap: nowrap;
  padding: 4px 0;
}

.cards--dealer .card + .card {
  margin-left: calc(var(--card-w) * -0.5);
}

.cards--dealer .card:nth-child(1) {
  z-index: 1;
}

.cards--dealer .card:nth-child(2) {
  z-index: 2;
}

.cards--dealer .card:nth-child(3) {
  z-index: 3;
}

.cards--dealer .card:nth-child(4) {
  z-index: 4;
}

.cards--dealer .card:nth-child(5) {
  z-index: 5;
}

.cards--dealer .card:nth-child(n + 6) {
  z-index: 6;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  flex-shrink: 0;
  position: relative;
  perspective: 800px;
}

.card__flipper {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.52s var(--ease-out);
  transform: rotateY(0deg);
}

.card--face-down .card__flipper {
  transform: rotateY(180deg);
}

.card--flipping .card__flipper {
  transition-duration: 0.52s;
}

.card__face {
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.card__face--front {
  background: var(--card-face);
  font-weight: 700;
  transform: rotateY(0deg);
}

.card__face--back {
  transform: rotateY(180deg);
  overflow: hidden;
  padding: 0;
  margin: 0;
  border: none;
  background-color: #0b1538;
  background-image: url("/assets/cards/tidebet-back.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.card-back-pattern {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  overflow: hidden;
}

.card--dealing {
  visibility: hidden;
}

.card-flight-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 40;
}

.card-flight-ghost {
  position: absolute;
  border-radius: var(--card-radius, 8px);
  background-color: #0b1538;
  background-image: url("/assets/cards/tidebet-back.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.card--red {
  color: #dc2626;
}

.card--black {
  color: #1e293b;
}

.card__corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
  font-size: 13px;
  gap: 1px;
}

.card__corner--tl {
  top: 6px;
  left: 7px;
}

.card__corner--br {
  bottom: 6px;
  right: 7px;
  transform: rotate(180deg);
}

.card__rank {
  display: block;
  font-size: 13px;
  line-height: 1.05;
}

.card__suit {
  display: block;
  font-size: 14px;
  line-height: 1;
}

.card__center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 30px;
  line-height: 1;
  opacity: 0.9;
  pointer-events: none;
}

.player-hands {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.player-hand {
  flex: 1 1 0;
  min-width: 0;
  max-width: calc((100% - 24px) / 3);
  padding: 12px 10px;
  border-radius: 16px;
  border: 1px solid transparent;
  transition:
    border-color 0.35s var(--ease-out),
    background 0.35s var(--ease-out),
    box-shadow 0.35s var(--ease-out);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.player-hands:has(.player-hand:only-child) .player-hand {
  flex: 0 1 520px;
  max-width: 520px;
}

.player-hands:has(.player-hand:first-child:nth-last-child(2)) .player-hand {
  max-width: calc((100% - 12px) / 2);
}

.player-hands:has(.player-hand:nth-child(3)) .cards {
  gap: 6px;
}

.player-hands:has(.player-hand:nth-child(3)) .card {
  width: 58px;
  height: 82px;
}

.player-hands:has(.player-hand:nth-child(3)) .card__corner {
  font-size: 11px;
}

.player-hands:has(.player-hand:nth-child(3)) .card__rank {
  font-size: 11px;
}

.player-hands:has(.player-hand:nth-child(3)) .card__suit {
  font-size: 12px;
}

.player-hands:has(.player-hand:nth-child(3)) .card__corner--tl {
  top: 5px;
  left: 5px;
}

.player-hands:has(.player-hand:nth-child(3)) .card__corner--br {
  bottom: 5px;
  right: 5px;
}

.player-hands:has(.player-hand:nth-child(3)) .card__center {
  font-size: 24px;
}

.player-hands:has(.player-hand:nth-child(3)) .hand-row__header {
  gap: 8px;
}

.player-hand--active {
  border-color: var(--tb-border, rgb(52 60 100));
  background: rgb(24 30 60);
  box-shadow: none;
}

.player-hand__result {
  font-size: 12px;
  font-weight: 600;
  margin-top: 10px;
  letter-spacing: 0.04em;
  animation: result-in 0.45s var(--ease-out) backwards;
}

@keyframes result-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.player-hand__result--win {
  color: var(--success);
}

.player-hand__result--lose {
  color: var(--danger);
}

.player-hand__result--push {
  color: var(--text-secondary);
}

.message-bar {
  text-align: center;
  min-height: 24px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  transition:
    opacity 0.35s var(--ease-out),
    color 0.35s var(--ease-out);
}

.message-bar--muted {
  opacity: 0.65;
}

.message-bar--win {
  color: var(--success);
}

.message-bar--lose {
  color: var(--danger);
}

.action-dock {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  min-height: 52px;
  padding: 4px;
  max-width: 1040px;
  width: 100%;
  transition:
    opacity 0.35s var(--ease-out),
    transform 0.35s var(--ease-out);
}

.action-dock--empty {
  opacity: 0;
  min-height: 0;
  padding: 0;
  pointer-events: none;
}

.action-dock .btn {
  animation: btn-in 0.4s var(--ease-out) backwards;
}

.action-dock .btn:nth-child(2) {
  animation-delay: 0.04s;
}

.action-dock .btn:nth-child(3) {
  animation-delay: 0.08s;
}

.action-dock .btn:nth-child(4) {
  animation-delay: 0.12s;
}

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

.action-dock__hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 4px;
}

#game-root .sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: rgba(26, 36, 51, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 18px;
  transition: opacity 0.35s var(--ease-out);
}

.panel--locked {
  opacity: 0.55;
  pointer-events: none;
}

.panel__title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.bet-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.bet-input {
  flex: 1;
  background: var(--bg-deep);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text-primary);
  padding: 12px 14px;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.bet-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.bet-input:disabled {
  opacity: 0.6;
}

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

.chip-row[hidden] {
  display: none;
}

.chip-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s var(--ease-out);
}

.chip-btn:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: rgba(124, 156, 255, 0.4);
  background: var(--bg-panel-hover);
}

.wallet-address {
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
  margin-top: 8px;
  line-height: 1.5;
}

.fair-note {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.55;
}

.fair-note code {
  font-size: 10px;
  color: var(--text-secondary);
  word-break: break-all;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  font-size: 12px;
}

.history-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.history-list .win {
  color: var(--success);
}

.history-list .lose {
  color: var(--danger);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.88);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
}

.modal p {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.55;
}

.modal__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.35s var(--ease-out);
}

.toast[hidden] {
  display: none;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .action-dock .btn,
  .toast {
    animation: none;
  }

  .btn,
  .action-dock,
  .message-bar,
  .player-hand {
    transition: none;
  }
}
