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

:root {
  --felt: #0d5c3d;
  --felt-deep: #084530;
  --felt-rim: #c9a227;
  --cream: #f5f0e6;
  --ink: #0f172a;
  --red: #dc2626;
  --win: #4ade80;
  --lose: #f87171;
  --push: #fbbf24;
}

html,
body {
  height: 100%;
  background: #061a12;
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Allow table column to paint bubbles above neighbors */
#app > .play-area {
  z-index: 1;
}

/* HUD */
#hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(0.65rem, env(safe-area-inset-top)) 0.9rem 0.4rem;
  flex-shrink: 0;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}

.hud-left {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem 1.1rem;
}

.hud-block,
.record-block,
.hand-meta {
  display: flex;
  flex-direction: column;
  min-width: 3.6rem;
}

.label {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.55;
}

.record-block span:last-child,
.hud-block span:last-child,
.hand-meta span:last-child {
  font-size: 1.05rem;
  font-weight: 700;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

/* Dealer / You sit to the right of Bet in the left cluster */
.hand-meta {
  padding-left: 0.65rem;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
}

.hand-meta.player-meta span:last-child {
  color: #a5f3fc;
}

.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  text-decoration: none;
  font-size: 1rem;
}

/* Play area: strategy left · table right · controls under table column
   DOM order: table → controls → strategy */
.play-area {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(15.5rem, min(22rem, 32vw)) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "strategy table"
    "strategy controls";
  gap: 0.55rem;
  padding: 0.25rem 0.65rem 0.15rem;
  align-items: stretch;
  /* visible so speech bubble / square can leave the felt */
  overflow: visible;
}

.table-wrap {
  grid-area: table;
}

.play-area > .controls {
  grid-area: controls;
}

.strategy {
  grid-area: strategy;
}

/* ── Strategy panel ───────────────────────────────── */
.strategy {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 0.85rem;
  border: 1px solid rgba(201, 162, 39, 0.28);
  background:
    linear-gradient(165deg, rgba(12, 32, 24, 0.97), rgba(6, 22, 16, 0.98));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  user-select: text;
}

.strategy-head {
  flex-shrink: 0;
  padding: 0.7rem 0.85rem 0.45rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.strategy-head h2 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fde68a;
}

.strategy-sub {
  margin-top: 0.2rem;
  font-size: 0.68rem;
  line-height: 1.35;
  color: rgba(245, 240, 230, 0.55);
}

.strategy-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem 0.25rem;
  flex-shrink: 0;
}

.strategy-legend .leg {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
  border-radius: 0.35rem;
  color: rgba(245, 240, 230, 0.9);
}

.strategy-legend .leg b {
  display: inline-grid;
  place-items: center;
  min-width: 1.35rem;
  height: 1.2rem;
  border-radius: 0.25rem;
  font-size: 0.72rem;
  font-weight: 800;
}

.strategy-legend .leg.h b,
.strat-table td.h {
  background: #166534;
  color: #bbf7d0;
}
.strategy-legend .leg.s b,
.strat-table td.s {
  background: #1e3a8a;
  color: #bfdbfe;
}
.strategy-legend .leg.d b,
.strat-table td.d,
.strat-table td.ds {
  background: #8f5806;
  color: #fef3c7;
}
.strategy-legend .leg.p b,
.strat-table td.p {
  background: #6b21a8;
  color: #e9d5ff;
}

.strategy-legend .leg.h {
  background: rgba(22, 101, 52, 0.25);
}
.strategy-legend .leg.s {
  background: rgba(30, 58, 138, 0.3);
}
.strategy-legend .leg.d {
  background: rgba(161, 98, 7, 0.28);
}
.strategy-legend .leg.p {
  background: rgba(107, 33, 168, 0.28);
}

.strategy-note {
  padding: 0.15rem 0.85rem 0.55rem;
  font-size: 0.65rem;
  line-height: 1.4;
  color: rgba(245, 240, 230, 0.5);
  flex-shrink: 0;
}

.strategy-note b {
  color: rgba(253, 230, 138, 0.85);
  font-weight: 700;
}

.strategy-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 0.65rem 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.strat-block {
  margin-bottom: 0.7rem;
}

.strat-block h3,
.strat-tips h3 {
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #86efac;
  margin-bottom: 0.35rem;
}

.strat-block h3 span {
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  opacity: 0.65;
  font-size: 0.68rem;
}

.strat-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
}

.strat-table thead th {
  font-size: 0.62rem;
  font-weight: 700;
  color: rgba(245, 240, 230, 0.55);
  padding: 0.15rem 0;
  text-align: center;
}

.strat-table thead th:first-child,
.strat-table tbody th {
  text-align: left;
  width: 3.4rem;
  padding-left: 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fde68a;
  white-space: nowrap;
}

.strat-table tbody th {
  color: rgba(245, 240, 230, 0.85);
  letter-spacing: -0.01em;
}

.strat-table td {
  text-align: center;
  font-weight: 800;
  font-size: 0.7rem;
  padding: 0.28rem 0;
  border-radius: 0.22rem;
  line-height: 1;
}

.strat-table td.ds {
  font-size: 0.58rem;
  letter-spacing: -0.03em;
}

/* Live strategy highlight — row + dealer column + intersection */
.strat-table tr.hl-row th {
  color: #fef08a !important;
  text-shadow: 0 0 8px rgba(250, 204, 21, 0.45);
}

.strat-table tr.hl-row td {
  box-shadow: inset 0 0 0 1px rgba(253, 224, 71, 0.35);
  filter: brightness(1.12);
}

.strat-table th.hl-col {
  color: #fef08a !important;
  text-shadow: 0 0 8px rgba(250, 204, 21, 0.45);
}

.strat-table td.hl-col {
  box-shadow: inset 0 0 0 1px rgba(253, 224, 71, 0.28);
  filter: brightness(1.08);
}

.strat-table td.hl-cell {
  outline: 2px solid #fde68a;
  outline-offset: -1px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 0 12px rgba(251, 191, 36, 0.55);
  filter: brightness(1.2);
  z-index: 1;
  position: relative;
  transform: scale(1.08);
}

.strat-table.hl-active {
  /* slight dim on non-active charts when a match exists */
}

.strat-block.hl-chart h3 {
  color: #fde68a;
}

.strat-block.hl-chart .strat-table {
  box-shadow: 0 0 0 1px rgba(253, 224, 71, 0.2);
  border-radius: 0.35rem;
}

.strat-tips ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.strat-tips li {
  font-size: 0.72rem;
  line-height: 1.4;
  color: rgba(245, 240, 230, 0.72);
  padding-left: 0.85rem;
  position: relative;
}

.strat-tips li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: #c9a227;
  font-size: 0.65rem;
  top: 0.1rem;
}

.strat-tips b {
  color: #fef3c7;
  font-weight: 750;
}

/* Table column — overflow visible so bubble/square can leave the felt */
.table-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 0.85rem 0.6rem; /* room for overflowed square/bubble */
  overflow: visible;
  position: relative;
  z-index: 1;
}

.felt {
  position: relative;
  /* Large table that fills available space (footer height is reserved, so this stays stable) */
  width: min(56rem, 100%);
  height: min(40rem, 100%);
  min-height: min(28rem, 100%);
  max-width: 100%;
  max-height: 100%;
  border-radius: 50% / 42%;
  /* Desktop: dealer top, player bottom (named areas — DOM order can differ) */
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "dealer"
    "player";
  align-items: stretch;
  justify-items: center;
  padding: clamp(0.7rem, 1.6vh, 1.15rem) clamp(1rem, 2.2vw, 1.75rem) clamp(0.75rem, 1.6vh, 1.35rem);
  /* allow square + speech to paint outside the rim */
  overflow: visible;
  z-index: 2;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Green surface is a fixed layer — size never depends on cards */
.felt::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, #127a52 0%, var(--felt) 45%, var(--felt-deep) 100%);
  border: 10px solid #5c4030;
  box-shadow:
    inset 0 0 0 4px var(--felt-rim),
    inset 0 0 60px rgba(0, 0, 0, 0.35),
    0 20px 50px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.felt > * {
  position: relative;
  z-index: 1;
}

.felt-logo {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 800;
  letter-spacing: 0.2em;
  font-size: clamp(0.7rem, 2.5vw, 1rem);
  color: rgba(201, 162, 39, 0.28);
  pointer-events: none;
}

.felt-rules {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  opacity: 0.35;
  white-space: nowrap;
  pointer-events: none;
}

.zone-label {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  opacity: 0.45;
  margin-top: 0.2rem;
  height: 1rem;
  line-height: 1rem;
  flex-shrink: 0;
}

.zone-label.you {
  margin-top: 0.25rem;
}

/* Status/bet under hands — reserved height so Win/Bust text doesn't reflow */
.hand-bet,
.hand-status {
  font-size: 0.72rem;
  font-weight: 650;
  margin-top: 0.15rem;
  min-height: 1rem;
  height: 1rem;
  line-height: 1rem;
}

/* Dealer zone — throne + centered cards (stable height) */
.dealer-zone {
  grid-area: dealer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  z-index: 5;
  width: 100%;
  min-height: 0;
  height: 100%;
  overflow: visible;
}

.house-stage {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  height: 5.6rem;
  min-height: 5.6rem;
  max-height: 5.6rem;
  flex-shrink: 0;
  overflow: visible;
  z-index: 8;
}

/* Royal red cushion + surrounding poker chips */
.house-throne {
  position: relative;
  width: 7.2rem;
  height: 5.6rem;
  display: grid;
  place-items: center;
  margin-bottom: 0;
  flex-shrink: 0;
  overflow: visible;
  z-index: 8;
}

/* Speech bubble — can paint outside the felt rim */
.speech-bubble {
  position: absolute;
  left: calc(50% + 3.55rem);
  top: -0.35rem;
  z-index: 20;
  max-width: min(13rem, 46vw);
  padding: 0.45rem 0.65rem 0.5rem;
  border-radius: 0.85rem 0.85rem 0.85rem 0.25rem;
  background: linear-gradient(165deg, #fffbeb, #fef3c7 70%, #fde68a);
  color: #1c1917;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(180, 83, 9, 0.2);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3;
  pointer-events: none;
  transform-origin: left bottom;
  /* fixed max height so long quips don't shove layout */
  max-height: 4.5rem;
  overflow: hidden;
}

.speech-bubble[hidden] {
  display: none !important;
}

.speech-bubble.show {
  display: block !important;
  animation: bubble-pop 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.speech-bubble.hide {
  animation: bubble-out 0.25s ease forwards;
}

.speech-bubble::before {
  content: "";
  position: absolute;
  left: -0.35rem;
  bottom: 0.55rem;
  width: 0.55rem;
  height: 0.55rem;
  background: #fef3c7;
  border-left: 2px solid rgba(255, 255, 255, 0.85);
  border-bottom: 2px solid rgba(255, 255, 255, 0.85);
  transform: rotate(45deg);
}

.speech-text {
  display: block;
}

@keyframes bubble-pop {
  from {
    opacity: 0;
    transform: scale(0.6) translate(-6px, 8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translate(0, 0);
  }
}

@keyframes bubble-out {
  to {
    opacity: 0;
    transform: scale(0.85) translateY(4px);
  }
}

.royal-cushion {
  position: relative;
  z-index: 2;
  width: 4.6rem;
  height: 3.85rem;
  border-radius: 48% 48% 42% 42% / 55% 55% 40% 40%;
  background:
    radial-gradient(ellipse 70% 55% at 50% 28%, rgba(255, 180, 180, 0.35), transparent 55%),
    radial-gradient(ellipse 90% 80% at 50% 70%, #7f1d1d 0%, #991b1b 35%, #450a0a 100%);
  border: 2px solid #fbbf24;
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.18),
    inset 0 -8px 14px rgba(0, 0, 0, 0.45),
    0 6px 16px rgba(0, 0, 0, 0.4),
    0 0 20px rgba(185, 28, 28, 0.35);
  display: grid;
  place-items: center;
  padding-top: 0.15rem;
}

.royal-cushion::before {
  content: "";
  position: absolute;
  inset: 0.28rem;
  border-radius: inherit;
  border: 1px dashed rgba(251, 191, 36, 0.45);
  pointer-events: none;
}

.crown-pip {
  position: absolute;
  top: -0.35rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  color: #fbbf24;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  z-index: 3;
  line-height: 1;
}

/* Decorative poker chips around the cushion */
.pchip {
  position: absolute;
  z-index: 1;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.15),
    0 2px 4px rgba(0, 0, 0, 0.35);
}

.pchip::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.pchip.pc1 { top: 0.15rem; left: 0.35rem; background: radial-gradient(circle at 35% 30%, #fca5a5, #b91c1c); }
.pchip.pc2 { top: 0.05rem; right: 0.45rem; background: radial-gradient(circle at 35% 30%, #fef3c7, #d97706); }
.pchip.pc3 { top: 1.55rem; left: 0; background: radial-gradient(circle at 35% 30%, #bfdbfe, #1d4ed8); }
.pchip.pc4 { top: 1.45rem; right: 0.05rem; background: radial-gradient(circle at 35% 30%, #bbf7d0, #15803d); }
.pchip.pc5 { bottom: 0.85rem; left: 0.2rem; background: radial-gradient(circle at 35% 30%, #e9d5ff, #7e22ce); }
.pchip.pc6 { bottom: 0.75rem; right: 0.25rem; background: radial-gradient(circle at 35% 30%, #fecdd3, #be123c); }
.pchip.pc7 { bottom: 0.15rem; left: 1.85rem; background: radial-gradient(circle at 35% 30%, #fef9c3, #ca8a04); width: 1rem; height: 1rem; }
.pchip.pc8 { bottom: 0.2rem; right: 1.7rem; background: radial-gradient(circle at 35% 30%, #e2e8f0, #475569); width: 1rem; height: 1rem; }

.dealer-square {
  width: 3.15rem;
  height: 3.15rem;
  border-radius: 0.5rem;
  background: linear-gradient(160deg, #c4b5fd, #7c3aed 55%, #5b21b6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 14px rgba(167, 139, 250, 0.5);
  display: grid;
  place-items: center;
  margin: 0;
  /* Face mood styles only — motion is animation-only, never layout */
  transition: filter 0.2s ease, box-shadow 0.2s ease;
  transform-origin: center center;
  position: relative;
  z-index: 9;
  will-change: transform;
  /* reactions may leap outside the cushion/felt */
  overflow: visible;
}

.dealer-square.deal-pulse {
  animation: deal-pulse-move 0.22s ease;
}

/* Hit — hop + lean toward the card */
.dealer-square.react-hit {
  animation: react-hit-move 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Stand — shrug / settle back */
.dealer-square.react-stand {
  animation: react-stand-move 0.72s cubic-bezier(0.22, 1, 0.36, 1);
}

.dealer-square.react-double {
  animation: react-double-move 0.56s cubic-bezier(0.22, 1, 0.36, 1);
}

.dealer-square.react-split {
  animation: react-split-move 0.56s ease;
}

.dealer-square.react-bounce {
  animation: react-bounce-move 0.45s ease;
}

@keyframes deal-pulse-move {
  0% {
    transform: scale(1) rotate(0);
  }
  40% {
    transform: scale(1.14) rotate(-8deg) translateY(-3px);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes react-hit-move {
  0% {
    transform: scale(1) rotate(0) translate(0, 0);
  }
  18% {
    transform: scale(0.92) rotate(-2deg) translateY(2px);
  }
  42% {
    transform: scale(1.22) rotate(-14deg) translate(-6px, -10px);
  }
  62% {
    transform: scale(1.1) rotate(8deg) translate(4px, -4px);
  }
  80% {
    transform: scale(1.05) rotate(-4deg) translateY(-2px);
  }
  100% {
    transform: scale(1) rotate(0) translate(0, 0);
  }
}

@keyframes react-stand-move {
  0% {
    transform: scale(1) rotate(0) translate(0, 0);
  }
  20% {
    transform: scale(1.08) rotate(6deg) translate(3px, -4px);
  }
  40% {
    transform: scale(0.96) rotate(-10deg) translate(-4px, 2px);
  }
  55% {
    transform: scale(1.04) rotate(4deg) translate(2px, -1px);
  }
  70% {
    transform: scale(0.98) rotate(-3deg) translateY(3px);
  }
  100% {
    transform: scale(1) rotate(0) translate(0, 0);
  }
}

@keyframes react-double-move {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.28) rotate(-12deg) translateY(-8px);
  }
  55% {
    transform: scale(0.94) rotate(6deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes react-split-move {
  0%,
  100% {
    transform: scale(1) rotate(0);
  }
  25% {
    transform: scale(1.15) rotate(-16deg) translateX(-8px);
  }
  50% {
    transform: scale(1.15) rotate(16deg) translateX(8px);
  }
  75% {
    transform: scale(1.1) rotate(-8deg);
  }
}

@keyframes react-bounce-move {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px) scale(1.08);
  }
  70% {
    transform: translateY(2px);
  }
}

.sq-face {
  position: relative;
  width: 1.75rem;
  height: 1.25rem;
}

/* Brows */
.sq-face .brow {
  position: absolute;
  top: -0.08rem;
  width: 0.48rem;
  height: 0.12rem;
  background: #0f172a;
  border-radius: 2px;
  transition: transform 0.15s ease, top 0.15s ease, width 0.15s ease, opacity 0.15s ease;
}

.sq-face .brow.left {
  left: 0.12rem;
  transform: rotate(0deg);
}

.sq-face .brow.right {
  right: 0.12rem;
  transform: rotate(0deg);
}

/* Eyes */
.sq-face .eye {
  position: absolute;
  top: 0.18rem;
  width: 0.34rem;
  height: 0.34rem;
  background: #0f172a;
  border-radius: 50%;
  transition:
    width 0.15s ease,
    height 0.15s ease,
    top 0.15s ease,
    left 0.15s ease,
    right 0.15s ease,
    border-radius 0.15s ease,
    transform 0.15s ease,
    background 0.15s ease;
}

.sq-face .eye.left {
  left: 0.14rem;
}

.sq-face .eye.right {
  right: 0.14rem;
}

/* Tiny shine on eyes */
.sq-face .eye::after {
  content: "";
  position: absolute;
  top: 0.05rem;
  right: 0.05rem;
  width: 0.1rem;
  height: 0.1rem;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  pointer-events: none;
}

/* Mouth — default soft smile */
.sq-face .mouth {
  position: absolute;
  left: 50%;
  bottom: 0.02rem;
  width: 0.72rem;
  height: 0.3rem;
  border: none;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0 0 50% 50%;
  transform: translateX(-50%);
  background: transparent;
  transition:
    width 0.15s ease,
    height 0.15s ease,
    bottom 0.15s ease,
    border-radius 0.15s ease,
    border 0.15s ease,
    background 0.15s ease,
    transform 0.15s ease;
}

/* Blush cheeks (hidden by default) */
.sq-face .cheek {
  position: absolute;
  bottom: 0.28rem;
  width: 0.28rem;
  height: 0.18rem;
  border-radius: 50%;
  background: rgba(244, 114, 182, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sq-face .cheek.left {
  left: -0.05rem;
}

.sq-face .cheek.right {
  right: -0.05rem;
}

/* ── Moods ─────────────────────────────────────────── */

/* Neutral smile */
.dealer-square[data-mood="idle"] {
  transform: none;
}

/* Dealing — focused lean */
.dealer-square[data-mood="deal"] {
  transform: scale(1.06) rotate(-6deg);
}
.dealer-square[data-mood="deal"] .brow.left {
  transform: rotate(12deg);
  top: 0;
}
.dealer-square[data-mood="deal"] .brow.right {
  transform: rotate(-12deg);
  top: 0;
}
.dealer-square[data-mood="deal"] .eye {
  height: 0.28rem;
  top: 0.2rem;
}
.dealer-square[data-mood="deal"] .mouth {
  width: 0.45rem;
  height: 0.12rem;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0;
  bottom: 0.12rem;
}

/* Thinking / watching player */
.dealer-square[data-mood="think"] {
  transform: rotate(4deg);
}
.dealer-square[data-mood="think"] .eye {
  transform: translateX(0.08rem);
}
.dealer-square[data-mood="think"] .brow.left {
  transform: rotate(-8deg);
}
.dealer-square[data-mood="think"] .brow.right {
  transform: rotate(-14deg);
  top: 0.02rem;
}
.dealer-square[data-mood="think"] .mouth {
  width: 0.4rem;
  height: 0.18rem;
  border-bottom: none;
  border: 2px solid #0f172a;
  border-radius: 50%;
  background: transparent;
  bottom: 0.08rem;
}

/* Hit — curious raised brows */
.dealer-square[data-mood="hit"] {
  transform: scale(1.08) translateY(-2px);
}
.dealer-square[data-mood="hit"] .brow.left,
.dealer-square[data-mood="hit"] .brow.right {
  top: -0.18rem;
  transform: rotate(0);
}
.dealer-square[data-mood="hit"] .eye {
  width: 0.4rem;
  height: 0.4rem;
  top: 0.12rem;
}
.dealer-square[data-mood="hit"] .mouth {
  width: 0.42rem;
  height: 0.38rem;
  border: 2.5px solid #0f172a;
  border-radius: 50%;
  border-bottom: 2.5px solid #0f172a;
  bottom: 0;
}

/* Stand — shrug / flat “fine.” */
.dealer-square[data-mood="stand"] {
  transform: scale(0.96) rotate(2deg);
}
.dealer-square[data-mood="stand"] .brow.left {
  transform: rotate(-18deg);
  top: 0.04rem;
}
.dealer-square[data-mood="stand"] .brow.right {
  transform: rotate(18deg);
  top: 0.04rem;
}
.dealer-square[data-mood="stand"] .eye {
  height: 0.14rem;
  border-radius: 2px;
  top: 0.28rem;
}
.dealer-square[data-mood="stand"] .eye::after {
  display: none;
}
.dealer-square[data-mood="stand"] .mouth {
  width: 0.55rem;
  height: 0;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0;
  bottom: 0.18rem;
}

/* Double — shocked */
.dealer-square[data-mood="double"] {
  transform: scale(1.14) rotate(-3deg);
  box-shadow: 0 0 22px rgba(251, 191, 36, 0.55);
}
.dealer-square[data-mood="double"] .brow.left,
.dealer-square[data-mood="double"] .brow.right {
  top: -0.22rem;
}
.dealer-square[data-mood="double"] .eye {
  width: 0.48rem;
  height: 0.48rem;
  top: 0.06rem;
  background: #fff;
  box-shadow: inset 0 0 0 0.12rem #0f172a;
}
.dealer-square[data-mood="double"] .eye::after {
  top: 0.12rem;
  right: 0.1rem;
  width: 0.12rem;
  height: 0.12rem;
  background: #0f172a;
}
.dealer-square[data-mood="double"] .mouth {
  width: 0.55rem;
  height: 0.5rem;
  border: 2.5px solid #0f172a;
  border-radius: 50%;
  bottom: -0.08rem;
}

/* Split — dizzy crossed eyes */
.dealer-square[data-mood="split"] {
  transform: scale(1.1) rotate(8deg);
  animation: sq-wobble 0.45s ease;
}
.dealer-square[data-mood="split"] .brow.left {
  transform: rotate(25deg);
}
.dealer-square[data-mood="split"] .brow.right {
  transform: rotate(-25deg);
}
.dealer-square[data-mood="split"] .eye.left {
  transform: rotate(-25deg) scaleX(1.2);
  border-radius: 40% 60% 50% 50%;
}
.dealer-square[data-mood="split"] .eye.right {
  transform: rotate(25deg) scaleX(1.2);
  border-radius: 60% 40% 50% 50%;
}
.dealer-square[data-mood="split"] .mouth {
  width: 0.7rem;
  height: 0.22rem;
  border-bottom: none;
  border-top: 2.5px solid #0f172a;
  border-radius: 50% 50% 0 0;
  bottom: 0.12rem;
  transform: translateX(-50%) rotate(-8deg);
}

@keyframes sq-wobble {
  0%,
  100% {
    transform: scale(1.1) rotate(8deg);
  }
  30% {
    transform: scale(1.12) rotate(-10deg);
  }
  60% {
    transform: scale(1.08) rotate(12deg);
  }
}

/* Insurance taken — sneaky */
.dealer-square[data-mood="sneaky"] {
  transform: scale(1.05) rotate(-5deg);
}
.dealer-square[data-mood="sneaky"] .brow.left {
  transform: rotate(18deg);
  top: 0.02rem;
}
.dealer-square[data-mood="sneaky"] .brow.right {
  transform: rotate(-6deg);
}
.dealer-square[data-mood="sneaky"] .eye.left {
  height: 0.18rem;
  border-radius: 2px;
  top: 0.26rem;
}
.dealer-square[data-mood="sneaky"] .eye.left::after {
  display: none;
}
.dealer-square[data-mood="sneaky"] .eye.right {
  transform: translateX(0.04rem);
}
.dealer-square[data-mood="sneaky"] .mouth {
  width: 0.85rem;
  height: 0.35rem;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0 0 60% 40%;
  transform: translateX(-42%);
}
.dealer-square[data-mood="sneaky"] .cheek {
  opacity: 0.7;
}

/* No insurance — pout */
.dealer-square[data-mood="pout"] {
  transform: scale(0.97);
}
.dealer-square[data-mood="pout"] .brow.left {
  transform: rotate(12deg);
  top: 0.02rem;
}
.dealer-square[data-mood="pout"] .brow.right {
  transform: rotate(-12deg);
  top: 0.02rem;
}
.dealer-square[data-mood="pout"] .eye {
  height: 0.22rem;
  top: 0.24rem;
}
.dealer-square[data-mood="pout"] .mouth {
  width: 0.5rem;
  height: 0.22rem;
  border-bottom: none;
  border-top: 2.5px solid #0f172a;
  border-radius: 50% 50% 0 0;
  bottom: 0.1rem;
}

/* Suspense / reveal — sweat drop + wide eyes */
.dealer-square[data-mood="suspense"] {
  transform: scale(1.08);
  animation: sq-shake 0.4s ease;
}
.dealer-square[data-mood="suspense"] .brow.left,
.dealer-square[data-mood="suspense"] .brow.right {
  top: -0.16rem;
}
.dealer-square[data-mood="suspense"] .eye {
  width: 0.42rem;
  height: 0.42rem;
  top: 0.1rem;
}
.dealer-square[data-mood="suspense"] .mouth {
  width: 0.35rem;
  height: 0.35rem;
  border: 2.5px solid #0f172a;
  border-radius: 50%;
  bottom: 0.02rem;
}
.dealer-square[data-mood="suspense"]::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  right: 0.15rem;
  width: 0.22rem;
  height: 0.32rem;
  background: #7dd3fc;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  opacity: 0.9;
  animation: sweat-drip 0.6s ease infinite alternate;
}

@keyframes sq-shake {
  0%,
  100% {
    transform: scale(1.08) translateX(0);
  }
  25% {
    transform: scale(1.08) translateX(-2px);
  }
  75% {
    transform: scale(1.08) translateX(2px);
  }
}

@keyframes sweat-drip {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(3px);
  }
}

/* Player bust — evil gloat laugh */
.dealer-square[data-mood="gloat"] {
  transform: scale(1.12) rotate(-4deg);
  filter: brightness(1.12);
  box-shadow: 0 0 24px rgba(250, 204, 21, 0.5);
}
.dealer-square[data-mood="gloat"] .brow.left {
  transform: rotate(22deg);
  top: 0.04rem;
}
.dealer-square[data-mood="gloat"] .brow.right {
  transform: rotate(-22deg);
  top: 0.04rem;
}
.dealer-square[data-mood="gloat"] .eye {
  height: 0.12rem;
  border-radius: 2px;
  top: 0.3rem;
}
.dealer-square[data-mood="gloat"] .eye::after {
  display: none;
}
.dealer-square[data-mood="gloat"] .mouth {
  width: 1rem;
  height: 0.45rem;
  border: none;
  border-bottom: 3px solid #0f172a;
  border-radius: 0 0 55% 55%;
  bottom: -0.05rem;
  background: rgba(15, 23, 42, 0.15);
}
.dealer-square[data-mood="gloat"] .cheek {
  opacity: 0.85;
}

/* Player blackjack / big win for player — panic */
.dealer-square[data-mood="panic"] {
  transform: scale(1.1) rotate(6deg);
  filter: saturate(1.2);
  animation: sq-panic 0.5s ease;
}
.dealer-square[data-mood="panic"] .brow.left {
  transform: rotate(-20deg);
  top: -0.12rem;
}
.dealer-square[data-mood="panic"] .brow.right {
  transform: rotate(20deg);
  top: -0.12rem;
}
.dealer-square[data-mood="panic"] .eye {
  width: 0.46rem;
  height: 0.46rem;
  top: 0.06rem;
  background: #fff;
  box-shadow: inset 0 0 0 0.11rem #0f172a;
}
.dealer-square[data-mood="panic"] .eye::after {
  top: 0.14rem;
  right: 0.08rem;
  width: 0.14rem;
  height: 0.14rem;
  background: #0f172a;
}
.dealer-square[data-mood="panic"] .mouth {
  width: 0.6rem;
  height: 0.55rem;
  border: 2.5px solid #0f172a;
  border-radius: 45%;
  bottom: -0.1rem;
}
.dealer-square[data-mood="panic"]::after {
  content: "";
  position: absolute;
  top: 0.15rem;
  right: 0.12rem;
  width: 0.2rem;
  height: 0.28rem;
  background: #7dd3fc;
  border-radius: 40% 40% 50% 50%;
}

@keyframes sq-panic {
  0%,
  100% {
    transform: scale(1.1) rotate(6deg);
  }
  40% {
    transform: scale(1.14) rotate(-8deg);
  }
}

/* Player wins round — sad */
.dealer-square[data-mood="sad"] {
  transform: scale(0.94) translateY(2px);
  filter: brightness(0.92) saturate(0.85);
}
.dealer-square[data-mood="sad"] .brow.left {
  transform: rotate(16deg);
  top: 0.06rem;
}
.dealer-square[data-mood="sad"] .brow.right {
  transform: rotate(-16deg);
  top: 0.06rem;
}
.dealer-square[data-mood="sad"] .eye {
  height: 0.2rem;
  top: 0.28rem;
  border-radius: 40% 40% 50% 50%;
}
.dealer-square[data-mood="sad"] .mouth {
  width: 0.55rem;
  height: 0.28rem;
  border-bottom: none;
  border-top: 2.5px solid #0f172a;
  border-radius: 50% 50% 0 0;
  bottom: 0.08rem;
}

/* Push — meh */
.dealer-square[data-mood="meh"] {
  transform: rotate(-2deg);
}
.dealer-square[data-mood="meh"] .brow.left,
.dealer-square[data-mood="meh"] .brow.right {
  top: 0.02rem;
  opacity: 0.85;
}
.dealer-square[data-mood="meh"] .eye {
  height: 0.16rem;
  border-radius: 2px;
  top: 0.28rem;
}
.dealer-square[data-mood="meh"] .eye::after {
  display: none;
}
.dealer-square[data-mood="meh"] .mouth {
  width: 0.48rem;
  height: 0;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0;
  bottom: 0.16rem;
  transform: translateX(-50%) rotate(-6deg);
}

/* Nice hand / player 21 — impressed */
.dealer-square[data-mood="wow"] {
  transform: scale(1.1);
}
.dealer-square[data-mood="wow"] .brow.left,
.dealer-square[data-mood="wow"] .brow.right {
  top: -0.2rem;
}
.dealer-square[data-mood="wow"] .eye {
  width: 0.44rem;
  height: 0.44rem;
  top: 0.08rem;
}
.dealer-square[data-mood="wow"] .mouth {
  width: 0.75rem;
  height: 0.4rem;
  border: none;
  border-bottom: 3px solid #0f172a;
  border-radius: 0 0 50% 50%;
  bottom: -0.02rem;
}
.dealer-square[data-mood="wow"] .cheek {
  opacity: 0.75;
}

/* Betting wait — bored blink */
.dealer-square[data-mood="bored"] {
  transform: scale(0.98);
}
.dealer-square[data-mood="bored"] .eye {
  height: 0.1rem;
  border-radius: 2px;
  top: 0.3rem;
}
.dealer-square[data-mood="bored"] .eye::after {
  display: none;
}
.dealer-square[data-mood="bored"] .mouth {
  width: 0.35rem;
  height: 0.12rem;
  border-bottom: 2px solid #0f172a;
  border-radius: 0;
  bottom: 0.16rem;
}

/* Chip select — interested */
.dealer-square[data-mood="chip"] {
  transform: scale(1.04) rotate(3deg);
}
.dealer-square[data-mood="chip"] .eye {
  transform: translateY(0.04rem);
}
.dealer-square[data-mood="chip"] .mouth {
  width: 0.65rem;
  height: 0.28rem;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0 0 55% 55%;
}

@media (prefers-reduced-motion: reduce) {
  .dealer-square[data-mood="split"],
  .dealer-square[data-mood="suspense"],
  .dealer-square[data-mood="panic"] {
    animation: none;
  }
}

/* Hand stack: fixed box — card count never changes felt size */
.hand-stack {
  position: relative;
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  width: min(26rem, 96%);
  min-height: 5.35rem;
  height: 5.35rem;
  margin: 0.15rem auto 0;
  flex-shrink: 0;
  overflow: visible;
}

/* Player hand — large readable cards */
.player-zone .hand-stack {
  min-height: 8.1rem;
  height: 8.1rem;
  width: min(36rem, 98%);
}

.player-zone .card-row {
  min-height: 7.6rem;
  height: 7.6rem;
}

.player-zone .card {
  width: 5.05rem;
  height: 7.05rem;
  margin-left: -1.05rem;
  font-size: 1.05rem;
  border-radius: 0.5rem;
}

.player-zone .card .corner {
  top: 0.28rem;
  left: 0.28rem;
  max-width: 1.65rem;
}

.player-zone .card .corner .cr {
  font-size: 1.02rem;
}

.player-zone .card .corner .cs {
  font-size: 0.9rem;
}

.player-zone .card .suit-lg {
  font-size: 1.9rem;
}

.player-zone .hand-total {
  font-size: 1.75rem;
  min-width: 2.7rem;
  padding: 0.36rem 0.55rem;
}

.hand-total {
  position: absolute;
  top: 0.15rem;
  left: calc(100% + 0.35rem);
  z-index: 4;
  min-width: 2.2rem;
  padding: 0.28rem 0.42rem;
  border-radius: 0.45rem;
  font-size: 1.4rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  letter-spacing: -0.03em;
  color: #0b1f16;
  background: linear-gradient(180deg, #fefce8, #fde68a);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.12),
    0 6px 16px rgba(0, 0, 0, 0.35);
  text-shadow: none;
  pointer-events: none;
  white-space: nowrap;
}

.hand-total.pop {
  animation: total-pop 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes total-pop {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.hand-total[hidden] {
  display: none !important;
}

.hand-total.soft {
  /* same big number; soft only tints ring slightly */
  box-shadow:
    0 0 0 2px rgba(56, 189, 248, 0.45),
    0 2px 0 rgba(0, 0, 0, 0.12),
    0 6px 16px rgba(0, 0, 0, 0.35);
}

.hand-total.bj {
  background: linear-gradient(180deg, #fef08a, #f59e0b);
  color: #1c1917;
}

.hand-total.bust {
  background: linear-gradient(180deg, #fecaca, #f87171);
  color: #450a0a;
}

.hand-total.dealer-hand-total {
  background: linear-gradient(180deg, #e9d5ff, #c4b5fd);
  color: #2e1065;
  border-color: rgba(255, 255, 255, 0.9);
}

.hand-total.dealer-hand-total.bust {
  background: linear-gradient(180deg, #fecaca, #f87171);
  color: #450a0a;
}

/* Cards — contained ranks/suits, fan toward center */
.card-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  min-height: 5.1rem;
  height: 5.1rem;
  gap: 0;
  /* card animations are transform-only; don't expand the row box */
  overflow: visible;
}

.card {
  width: 3.25rem;
  height: 4.55rem;
  border-radius: 0.38rem;
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.14);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  margin-left: -0.7rem;
  display: block;
  padding: 0;
  font-weight: 700;
  font-size: 0.78rem;
  position: relative;
  overflow: hidden; /* keep rank/suit inside border */
  flex-shrink: 0;
  transform-origin: bottom center;
  animation: deal-in 0.52s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.card-row .card:first-child {
  margin-left: 0;
}

.card.red {
  color: var(--red);
}

.card.back {
  background: linear-gradient(145deg, #1e3a8a, #312e81 40%, #1e3a8a);
  color: transparent;
  border-color: #1e293b;
}

.card.back::after {
  content: "♠";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.35);
  font-size: 1.25rem;
  animation: none;
}

.card .corner {
  position: absolute;
  top: 0.18rem;
  left: 0.18rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
  text-align: center;
  max-width: 1.2rem;
  overflow: hidden;
}

.card .corner .cr {
  font-size: 0.7rem;
  letter-spacing: -0.04em;
}

.card .corner .cs {
  font-size: 0.62rem;
  margin-top: 0.02rem;
}

.card .corner .cr:only-child {
  font-size: 0.7rem;
}

.card .suit-lg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 1.2rem;
  line-height: 1;
  pointer-events: none;
}

.card .corner.bl {
  top: auto;
  left: auto;
  bottom: 0.22rem;
  right: 0.22rem;
  transform: rotate(180deg);
}

@keyframes deal-in {
  0% {
    opacity: 0;
    transform: translateY(-3.2rem) translateX(2.2rem) rotate(-18deg) scale(0.7);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
  }
  55% {
    opacity: 1;
    transform: translateY(0.18rem) translateX(-0.08rem) rotate(3deg) scale(1.04);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
  }
  78% {
    transform: translateY(-0.1rem) translateX(0.04rem) rotate(-1.5deg) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) translateX(0) rotate(0) scale(1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  }
}

.card.no-anim {
  animation: none;
}

@keyframes flip-reveal {
  0% {
    transform: rotateY(92deg) scale(0.92) translateY(-0.2rem);
    filter: brightness(0.85);
  }
  40% {
    transform: rotateY(-12deg) scale(1.06) translateY(0.05rem);
    filter: brightness(1.1);
  }
  70% {
    transform: rotateY(5deg) scale(1.02);
  }
  100% {
    transform: rotateY(0) scale(1) translateY(0);
    filter: brightness(1);
  }
}

.card.flip-reveal {
  animation: flip-reveal 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  transform-style: preserve-3d;
}

/* Soft land when a hit card arrives */
@keyframes card-nudge {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-0.2rem) scale(1.03);
  }
}

.message {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: min(90%, 22rem);
  min-height: 1.5rem;
  max-height: 2.6rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.25;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  color: #fef3c7;
  pointer-events: none;
  /* fixed footprint so text changes never reflow the table */
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.message.push {
  color: var(--push);
}

/* Player zone — fixed bottom half of felt grid */
.player-zone {
  grid-area: player;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  margin: 0;
  transform: none;
  padding-bottom: 0.25rem;
  overflow: visible;
}

.player-zone .hand-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.player-zone .hand-slot[data-active="true"] .card-row {
  filter: drop-shadow(0 0 10px rgba(125, 211, 252, 0.45));
}

.player-zone .hand-slot.hidden {
  display: none;
}

.player-zone.split-mode {
  flex-direction: row;
  justify-content: center;
  gap: 1.5rem;
  align-items: center;
  min-height: 0;
}

.player-zone.split-mode .zone-label.you {
  position: absolute;
  bottom: 0.2rem;
  left: 50%;
  transform: translateX(-50%);
}

.hand-status.win {
  color: var(--win);
}

.hand-status.lose {
  color: var(--lose);
}

.hand-status.push {
  color: var(--push);
}

/* Controls — reserved height so Deal/Hit/Next swap never resizes the table */
.controls,
.play-area > .controls {
  flex-shrink: 0;
  padding: 0.55rem 0.9rem max(0.75rem, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.35));
  text-align: center;
  min-height: 6.75rem;
  box-sizing: border-box;
  align-self: end;
}

.controls-stage {
  position: relative;
  min-height: 3.1rem;
  margin-bottom: 0.35rem;
}

.bet-row,
.action-row,
.result-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  align-items: center;
  margin-bottom: 0;
  min-height: 3.1rem;
}

/* Keep footprint when a row is hidden so the felt doesn't jump */
.controls-stage .bet-row[hidden],
.controls-stage .action-row[hidden],
.controls-stage .result-row[hidden] {
  display: flex !important;
  visibility: hidden;
  pointer-events: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  opacity: 0;
  z-index: 0;
}

.controls-stage .bet-row:not([hidden]),
.controls-stage .action-row:not([hidden]),
.controls-stage .result-row:not([hidden]) {
  position: relative;
  z-index: 1;
}

.ctrl-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.55;
  margin-right: 0.25rem;
}

.chip {
  min-width: 3rem;
  padding: 0.45rem 0.55rem;
  border-radius: 999px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  background: radial-gradient(circle at 30% 30%, #fef3c7, #d97706 70%);
  color: #1c1917;
  font-weight: 800;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip.active {
  outline: 2px solid #fde68a;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.45);
}

.chip.chip-allin {
  background: radial-gradient(circle at 30% 30%, #fecaca, #dc2626 70%);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.45);
  min-width: 3.6rem;
}

.chip.chip-allin.active {
  outline-color: #fca5a5;
  box-shadow: 0 0 14px rgba(248, 113, 113, 0.5);
}

.chip:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn {
  min-width: 5.2rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

/* "A: Hit" key prefix on action buttons */
.btn .key-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fde68a;
  margin-right: 0.1rem;
}

.btn.primary .key-label {
  color: #1c1917;
}

.btn.key-flash {
  outline: 2px solid #fde68a;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35);
  background: rgba(253, 230, 138, 0.22);
  transform: scale(1.04);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn.primary {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: transparent;
  color: #1c1917;
}

.btn.ghost {
  background: transparent;
  opacity: 0.85;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Individual action buttons can still collapse; control rows keep footprint */
.btn[hidden] {
  display: none !important;
}

.hint {
  font-size: 0.68rem;
  opacity: 0.4;
  margin-top: 0.15rem;
}

.version {
  margin-top: 0.35rem;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  opacity: 0.4;
  color: #86efac;
}

/* Side-by-side as long as width allows */
@media (max-width: 1100px) {
  .play-area {
    grid-template-columns: minmax(14.5rem, 18rem) minmax(0, 1fr);
    gap: 0.45rem;
  }

  .strategy-head {
    padding: 0.55rem 0.65rem 0.35rem;
  }

  .strategy-note {
    font-size: 0.6rem;
  }

  .strat-table {
    font-size: 0.62rem;
    border-spacing: 1px;
  }

  .strat-table td {
    font-size: 0.6rem;
    padding: 0.2rem 0;
  }

  .strat-table thead th:first-child,
  .strat-table tbody th {
    width: 2.9rem;
    font-size: 0.6rem;
  }
}

/*
 * Mobile / narrow (≤900px):
 *  - Full page scroll
 *  - Table first (expanded), strategy guide below (scroll to it)
 *  - Flex side-by-side hands: YOU left · HOUSE right (not stacked)
 */
@media (max-width: 900px) {
  .felt::before {
    border-width: 8px;
  }

  html,
  body {
    height: auto !important;
    min-height: 100%;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #app {
    height: auto !important;
    min-height: calc(100dvh - var(--rg-bar));
    overflow: visible !important;
    display: flex;
    flex-direction: column;
  }

  .play-area {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    grid-template-areas: none !important;
    flex: none !important;
    width: 100%;
    min-height: 0;
    height: auto !important;
    overflow: visible !important;
    gap: 0.75rem;
    padding: 0.2rem 0.4rem 0.5rem;
  }

  .table-wrap {
    grid-area: auto !important;
    order: 1;
    flex: none;
    width: 100%;
    height: auto !important;
    min-height: 0;
    padding: 0.15rem 0.1rem 0.15rem;
    display: block !important;
    place-items: unset;
  }

  /* Bet options directly under table, above BSG */
  .play-area > .controls {
    grid-area: auto !important;
    order: 2;
    flex: none !important;
    width: 100%;
    position: relative;
    bottom: auto;
    z-index: 5;
    min-height: 0;
    padding: 0.45rem 0.35rem 0.55rem;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.4));
    border-radius: 0.65rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
  }

  .strategy {
    grid-area: auto !important;
    order: 3;
    flex: none !important;
    width: 100%;
    max-height: none !important;
    min-height: 0;
    height: auto !important;
    overflow: visible !important;
  }

  .strategy-scroll {
    flex: none !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .strat-tips {
    display: block;
  }

  /* —— Felt: flex row, not 2-row grid —— */
  .felt {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    min-height: 16rem !important;
    max-height: none !important;
    border-radius: 1rem !important;
    padding: 0.65rem 0.4rem 0.7rem !important;
    gap: 0;
    overflow: visible !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    grid-template-areas: none !important;
  }

  .felt-logo,
  .felt-rules {
    display: none !important;
  }

  /* Player left half */
  .player-zone {
    grid-area: auto !important;
    order: 1 !important;
    flex: 1 1 48% !important;
    width: 48% !important;
    max-width: 50%;
    height: auto !important;
    min-height: 12rem;
    box-sizing: border-box;
    justify-content: flex-start !important;
    align-items: center !important;
    padding: 0.25rem 0.35rem 0.35rem !important;
    border-right: 1px dashed rgba(255, 255, 255, 0.18);
    border-bottom: none !important;
    overflow: visible !important;
  }

  /* Dealer right half — house shifted toward the right edge */
  .dealer-zone {
    grid-area: auto !important;
    order: 2 !important;
    flex: 1 1 48% !important;
    width: 48% !important;
    max-width: 50%;
    height: auto !important;
    min-height: 12rem;
    box-sizing: border-box;
    justify-content: flex-start !important;
    align-items: flex-end !important;
    padding: 0.25rem 0.2rem 0.35rem 0.35rem !important;
    border-bottom: none !important;
    overflow: visible !important;
  }

  /* Message full width under both hands */
  .message {
    grid-area: auto !important;
    order: 3 !important;
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: none !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    min-height: 1.4rem;
    max-height: none !important;
    font-size: 0.85rem;
    margin: 0.15rem 0 0;
    padding: 0.3rem 0.4rem;
  }

  .house-stage {
    position: relative !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin-bottom: 0.15rem;
    width: 100%;
    display: flex !important;
    justify-content: flex-end !important;
    align-items: flex-start !important;
    overflow: visible !important;
    /* Room on the left for speech bubble next to Squipy */
    padding-left: 0.25rem;
    box-sizing: border-box;
  }

  .house-throne {
    width: 4.2rem;
    height: 3.4rem;
    margin-left: auto;
    margin-right: 0.05rem;
    flex-shrink: 0;
  }

  .royal-cushion {
    width: 2.9rem;
    height: 2.5rem;
  }

  .dealer-square {
    width: 2.25rem;
    height: 2.25rem;
  }

  .zone-label {
    font-size: 0.58rem;
    margin: 0.1rem 0.15rem 0.25rem 0;
    height: auto;
    text-align: right;
    width: 100%;
  }

  .dealer-zone .zone-label {
    text-align: right;
    padding-right: 0.35rem;
  }

  .player-zone .zone-label.you {
    order: -1;
    margin-bottom: 0.2rem;
    text-align: center;
    width: auto;
  }

  .dealer-zone .hand-stack {
    align-self: flex-end;
    width: 100%;
  }

  .hand-stack {
    position: relative;
    display: flex !important;
    flex-direction: column !important;
    align-items: center;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
  }

  .card-row,
  .player-zone .card-row,
  .dealer-zone .card-row {
    width: 100%;
    height: auto !important;
    min-height: 3.5rem !important;
    justify-content: center;
  }

  .hand-total,
  .player-zone .hand-total,
  .hand-total.dealer-hand-total {
    position: static !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    margin: 0.28rem auto 0 !important;
    font-size: 1rem;
    min-width: 1.8rem;
    padding: 0.16rem 0.3rem;
    transform: none !important;
  }

  /* Compact cards — force override of large desktop player cards */
  .card,
  .player-zone .card,
  .dealer-zone .card,
  .player-zone .hand-slot .card {
    width: 2.5rem !important;
    height: 3.5rem !important;
    margin-left: -0.52rem !important;
    font-size: 0.68rem !important;
    border-radius: 0.3rem;
  }

  .card-row .card:first-child {
    margin-left: 0 !important;
  }

  .player-zone .card .corner .cr,
  .card .corner .cr {
    font-size: 0.7rem !important;
  }

  .player-zone .card .suit-lg,
  .card .suit-lg {
    font-size: 1.1rem !important;
  }

  .player-zone .hand-stack,
  .dealer-zone .hand-stack {
    width: 100% !important;
    min-height: 0 !important;
    height: auto !important;
  }

  /* Speech to the LEFT of Squipy / house (not below) */
  .speech-bubble {
    left: auto !important;
    right: calc(4.2rem + 0.35rem) !important; /* throne width + gap */
    top: 0.15rem !important;
    bottom: auto !important;
    transform: none;
    max-width: min(7.25rem, calc(100% - 4.7rem)) !important;
    width: max-content;
    font-size: 0.62rem;
    max-height: 3.6rem;
    border-radius: 0.7rem 0.7rem 0.2rem 0.7rem !important;
    text-align: left;
    z-index: 25;
  }

  .speech-bubble::before {
    /* Tail points right toward Squipy */
    left: auto !important;
    right: -0.28rem !important;
    top: 0.65rem !important;
    bottom: auto !important;
    transform: rotate(45deg);
    border-left: none !important;
    border-bottom: none !important;
    border-right: 2px solid rgba(255, 255, 255, 0.85) !important;
    border-top: 2px solid rgba(255, 255, 255, 0.85) !important;
    background: #fef3c7;
  }

  .speech-bubble.show {
    animation-name: bubble-pop-mobile-left;
  }

  @keyframes bubble-pop-mobile-left {
    from {
      opacity: 0;
      transform: scale(0.7) translateX(6px);
    }
    to {
      opacity: 1;
      transform: scale(1) translateX(0);
    }
  }

  .player-zone.split-mode {
    flex-direction: column !important;
    gap: 0.4rem;
  }

  .player-zone.split-mode .zone-label.you {
    position: static !important;
    transform: none !important;
  }

  .player-zone.split-mode .card {
    width: 2.15rem !important;
    height: 3rem !important;
    margin-left: -0.45rem !important;
  }

  .hint {
    display: none;
  }

  .play-area > .controls .version {
    margin-top: 0.25rem;
  }
}

@media (max-width: 560px) {
  #hud {
    padding: max(0.4rem, env(safe-area-inset-top)) 0.45rem 0.15rem;
    gap: 0.35rem;
  }

  .felt {
    min-height: 15rem !important;
    padding: 0.5rem 0.3rem 0.55rem !important;
  }

  .player-zone,
  .dealer-zone {
    min-height: 11rem;
    padding: 0.2rem 0.25rem !important;
  }

  .card,
  .player-zone .card,
  .dealer-zone .card,
  .player-zone .hand-slot .card {
    width: 2.3rem !important;
    height: 3.2rem !important;
    margin-left: -0.48rem !important;
  }

  .card-row,
  .player-zone .card-row,
  .dealer-zone .card-row {
    min-height: 3.25rem !important;
  }

  .house-throne {
    width: 3.7rem;
    height: 3rem;
  }

  .dealer-square {
    width: 2.05rem;
    height: 2.05rem;
  }

  .speech-bubble {
    right: calc(3.7rem + 0.3rem) !important;
    max-width: min(6.5rem, calc(100% - 4.2rem)) !important;
    font-size: 0.58rem;
  }

  .dealer-zone {
    align-items: flex-end !important;
    padding-right: 0.1rem !important;
  }

  .btn {
    min-width: 4.1rem;
    padding: 0.42rem 0.48rem;
    font-size: 0.76rem;
  }
}

/* Short viewports — desktop / wide only (mobile uses auto-height stack above) */
@media (max-height: 780px) and (min-width: 721px) {
  .play-area {
    padding-top: 0.1rem;
  }

  .felt {
    height: min(34rem, 100%);
    min-height: min(20rem, 100%);
    padding-top: 0.55rem;
    padding-bottom: 0.6rem;
  }

  .hand-stack {
    height: 4.4rem;
    min-height: 4.4rem;
  }

  .card-row {
    height: 4.4rem;
    min-height: 4.4rem;
  }

  .card {
    width: 2.7rem;
    height: 3.85rem;
  }

  .strategy-head {
    padding: 0.45rem 0.6rem 0.3rem;
  }

  .strat-table td {
    padding: 0.16rem 0;
  }

  .strat-tips li {
    font-size: 0.66rem;
    gap: 0.25rem;
  }

  .controls {
    min-height: 5.75rem;
    padding-top: 0.35rem;
    padding-bottom: max(0.45rem, env(safe-area-inset-bottom));
  }

  .hint {
    display: none;
  }
}

@media (max-height: 640px) and (min-width: 721px) {
  .card {
    width: 2.35rem;
    height: 3.35rem;
    margin-left: -0.55rem;
    font-size: 0.68rem;
  }

  .hand-total {
    font-size: 1.1rem;
    min-width: 1.85rem;
    padding: 0.18rem 0.3rem;
  }

  .dealer-square {
    width: 2.55rem;
    height: 2.55rem;
  }

  .house-throne {
    width: 5.8rem;
    height: 4.6rem;
  }

  .royal-cushion {
    width: 3.8rem;
    height: 3.2rem;
  }

  .strat-tips {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .card.flip-reveal,
  .hand-total.pop,
  .dealer-square.deal-pulse,
  .dealer-square.react-hit,
  .dealer-square.react-stand,
  .dealer-square.react-double,
  .dealer-square.react-split,
  .dealer-square.react-bounce,
  .speech-bubble.show,
  .speech-bubble.hide {
    animation: none;
  }
}
