/* Cosmic Blackjack — Pro UI: premium table, cards, chips, animations */

/* -------------------------------------------------------------------------
   Animation speed: CSS variables (JS sets .bj-fast / .bj-slow on body)
   ------------------------------------------------------------------------- */
:root {
  --deal-ms: 420;
  --flip-ms: 480;
  --result-ms: 1800;
}
body.bj-fast {
  --deal-ms: 260;
  --flip-ms: 280;
  --result-ms: 1200;
}
body.bj-slow {
  --deal-ms: 580;
  --flip-ms: 620;
  --result-ms: 2400;
}

/* -------------------------------------------------------------------------
   Premium table (felt + lighting + edge)
   ------------------------------------------------------------------------- */
.bj-table.bj-felt {
  position: relative;
  border-radius: 20px;
  overflow: visible;
  /* Table rail: visible edge for depth */
  border: 4px solid rgba(25, 55, 40, 0.95);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 0 120px rgba(0, 0, 0, 0.25),
    inset 0 2px 0 rgba(255, 255, 255, 0.04),
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 4px 0 rgba(15, 35, 25, 0.9),
    0 8px 32px rgba(0, 0, 0, 0.4);
  background-color: #0a1f14;
  /* Noise texture simulation */
  background-image:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 120% 80% at 50% 45%, rgba(40, 90, 70, 0.35), transparent 55%),
    radial-gradient(ellipse 100% 60% at 50% 50%, rgba(30, 70, 60, 0.5), transparent 50%),
    linear-gradient(165deg, #0d2818 0%, #0a1f14 40%, #071a10 100%);
  display: flex;
  flex-direction: column;
  min-height: 180px;
}

/* Spotlight / center glow */
.bj-table.bj-felt::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 50% at 50% 45%, rgba(80, 160, 120, 0.12), transparent 60%);
  border-radius: inherit;
}

/* Vignette */
.bj-table.bj-felt::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 80px 20px rgba(0, 0, 0, 0.35);
}

/* Shoe position (top-right) */
.bj-shoe {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 52px;
  height: 40px;
  background: linear-gradient(180deg, #1a2520 0%, #0f1612 100%);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

/* Discard tray */
.bj-discard {
  position: absolute;
  bottom: 12px;
  right: 16px;
  width: 48px;
  height: 36px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  z-index: 1;
}

/* Table zones container — cards sit on the felt, no overlap below */
.bj-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 20px 18px;
  position: relative;
  z-index: 1;
  overflow: visible;
  min-height: 260px;
}

/* Dealer hand zone — subtle zone glow */
.bj-hand {
  position: relative;
}
.bj-hand:first-of-type {
  flex-shrink: 0;
  margin-bottom: 8px;
  border-radius: 12px;
  box-shadow: inset 0 0 60px rgba(60, 120, 90, 0.06);
}
/* Dealer hand — a bit down from top so cards sit on felt */
.bj-hand:first-of-type {
  margin-top: 4px;
  flex-shrink: 0;
}
.bj-hand:first-of-type .bj-cards { min-height: 72px; }

/* Player hand — room for cards + result label (WIN/LOSE/PUSH) below */
.bj-hand:last-of-type {
  flex-shrink: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 60px rgba(60, 120, 90, 0.06);
  margin-top: 4px;
  margin-bottom: 14px;
  padding-bottom: 36px; /* space for .bj-result-label (bottom: -8px) so it's not clipped */
  min-height: 100px;
  overflow: visible;
}
.bj-hand:last-of-type .bj-hand-title { margin-bottom: 4px; }
.bj-hand:last-of-type .bj-cards { margin-top: 4px; min-height: 88px; overflow: visible; }
.bj-hand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.bj-hand-title .tag.on { color: var(--good); border-color: rgba(140, 255, 178, 0.35); }
.bj-score { font-variant-numeric: tabular-nums; }

/* Cards row — gap and stacking so cards don't overlap */
.bj-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 88px;
  align-items: flex-start;
  align-content: flex-start;
}
.bj-cards .bj-card {
  flex-shrink: 0;
}

/* -------------------------------------------------------------------------
   Professional cards
   ------------------------------------------------------------------------- */
.bj-card {
  width: 64px;
  height: 88px;
  min-width: 64px;
  min-height: 88px;
  border-radius: 8px;
  background: linear-gradient(165deg, #fafafa 0%, #e8e8e8 100%);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}
.bj-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, transparent 100%);
  border-radius: 8px 8px 0 0;
  pointer-events: none;
}
.bj-card .r,
.bj-card .s {
  color: #1a1a1a;
}
.bj-card .r {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}
.bj-card .s {
  font-size: 20px;
  line-height: 1;
  margin-top: 2px;
}
.bj-card.red .r,
.bj-card.red .s { color: #c03030; }

/* Card back (dealer hole card) */
.bj-card.back {
  background: transparent;
  border-color: rgba(122, 168, 255, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.bj-card.back::before { display: none; }
.bj-card.back::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 6px;
  background: url(/assets/bj/card-back.svg) center/100% 100% no-repeat;
}

/* Deal animation: fly from shoe to slot */
.bj-card.deal {
  animation: bj-deal calc(var(--deal-ms) * 1ms) cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  transform: translate(var(--fx, -90px), var(--fy, -60px)) scale(0.85);
  opacity: 0;
}
.bj-card.deal .r,
.bj-card.deal .s { opacity: 0; }
@keyframes bj-deal {
 0% {
   transform: translate(var(--fx, -90px), var(--fy, -60px)) scale(0.85);
   opacity: 0;
 }
 70% { opacity: 1; }
 100% {
   transform: translate(0, 0) scale(1);
   opacity: 1;
 }
}
.bj-card.deal .r,
.bj-card.deal .s { animation: bj-deal-fade calc(var(--deal-ms) * 0.8ms) calc(var(--d, 0) * 1ms) forwards; opacity: 0; }
.bj-card.first-card .r,
.bj-card.first-card .s { opacity: 1; animation: none; }
@keyframes bj-deal-fade {
  to { opacity: 1; }
}

/* Stagger delay for multiple cards */
.bj-card.deal { animation-delay: calc(var(--d, 0) * 1ms); }

/* Flip animation (dealer reveal) */
.bj-card.flip {
  animation: bj-flip calc(var(--flip-ms) * 1ms) cubic-bezier(0.35, 0.1, 0.25, 1) forwards;
}
@keyframes bj-flip {
 0% { transform: rotateY(0deg); }
 50% { transform: rotateY(90deg); }
 100% { transform: rotateY(0deg); }
}
.bj-card.flip::after {
  animation: bj-flip-back calc(var(--flip-ms) * 1ms) cubic-bezier(0.35, 0.1, 0.25, 1) forwards;
}
@keyframes bj-flip-back {
  0% { opacity: 1; }
  49% { opacity: 1; }
  50% { opacity: 0; }
  100% { opacity: 0; }
}

/* Glint on new cards */
.bj-card.glint::before {
  animation: bj-glint 0.6s ease-out;
}
@keyframes bj-glint {
  from { opacity: 0.8; }
  to { opacity: 0; }
}

/* Discard: fly to tray */
.bj-card.discard {
  animation: bj-discard-anim 520ms cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
  pointer-events: none;
  z-index: 10;
}
@keyframes bj-discard-anim {
  to {
    transform: translate(var(--dx, 0), var(--dy, 0)) scale(0.6);
    opacity: 0;
  }
}

/* Result glow on table */
.bj-felt.result-win::before {
  background: radial-gradient(ellipse 80% 50% at 50% 45%, rgba(140, 255, 178, 0.2), transparent 60%);
  animation: bj-result-flash calc(var(--result-ms) * 1ms) ease-out;
}
.bj-felt.result-lose::before {
  background: radial-gradient(ellipse 80% 50% at 50% 45%, rgba(255, 122, 140, 0.12), transparent 60%);
  animation: bj-result-flash calc(var(--result-ms) * 1ms) ease-out;
}
.bj-felt.result-push::before {
  background: radial-gradient(ellipse 80% 50% at 50% 45%, rgba(255, 211, 122, 0.12), transparent 60%);
  animation: bj-result-flash calc(var(--result-ms) * 1ms) ease-out;
}
@keyframes bj-result-flash {
  from { opacity: 1; }
  to { opacity: 0.4; }
}

/* Mid zone: bet circle + status — tighter so hands fit on table */
.bj-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin: 6px 0;
}
.bj-bet-circle {
  width: 100%;
  max-width: 200px;
  min-height: 72px;
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.15);
  position: relative;
  box-shadow: inset 0 0 40px rgba(80, 160, 120, 0.08);
}
.bj-bet-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
}
.bj-bet-stack {
  position: relative;
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bet stack chips (small, stacked) */
.bj-bet-stack .bj-chip.in {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  font-size: 0;
}

/* Status pill (phase label) */
.bj-status {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Result label (WIN/LOSE/PUSH) — visible above next section */
.bj-result-label {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding: 6px 14px;
  border-radius: 999px;
  z-index: 10;
  animation: bj-result-label-in calc(var(--result-ms) * 0.4ms) ease-out;
}
.bj-result-label.win { background: rgba(140, 255, 178, 0.25); color: var(--good); border: 1px solid rgba(140, 255, 178, 0.4); }
.bj-result-label.lose { background: rgba(255, 122, 140, 0.2); color: var(--bad); border: 1px solid rgba(255, 122, 140, 0.35); }
.bj-result-label.push { background: rgba(255, 211, 122, 0.2); color: var(--warn); border: 1px solid rgba(255, 211, 122, 0.35); }
@keyframes bj-result-label-in {
  from { transform: translateX(-50%) scale(0.8); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* -------------------------------------------------------------------------
   Realistic chips (use SVG assets)
   ------------------------------------------------------------------------- */
.bj-chips {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
}
.bj-chips .bj-chip-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border: none;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
  transition: transform 0.12s ease, filter 0.12s ease;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
.bj-chips .bj-chip-btn:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.08);
  filter: brightness(1.15);
}
.bj-chips .bj-chip-btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}
.bj-chips .bj-chip-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.bj-chips .bj-chip-btn[data-v="1"] { background-image: url(/assets/bj/chip-1.svg); }
.bj-chips .bj-chip-btn[data-v="5"] { background-image: url(/assets/bj/chip-5.svg); }
.bj-chips .bj-chip-btn[data-v="10"] { background-image: url(/assets/bj/chip-10.svg); }
.bj-chips .bj-chip-btn[data-v="25"] { background-image: url(/assets/bj/chip-25.svg); }
.bj-chips .bj-chip-btn[data-v="50"] { background-image: url(/assets/bj/chip-50.svg); }

/* Chip fly (bet animation) */
.chip-fly {
  position: fixed;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: #1a1a1a;
  background: url(/assets/bj/chip-1.svg) center/100% 100% no-repeat;
  z-index: 9998;
  pointer-events: none;
}
.chip-fly.win { background-image: url(/assets/bj/chip-25.svg); }
.chip-fly.lose { background-image: url(/assets/bj/chip-5.svg); }

/* -------------------------------------------------------------------------
   Game phase UI (state clarity)
   ------------------------------------------------------------------------- */
body.phase-betting .bj-status { border-color: rgba(122, 168, 255, 0.35); background: rgba(122, 168, 255, 0.12); }
body.phase-betting .bj-chips .bj-chip-btn { box-shadow: 0 0 0 2px rgba(122, 168, 255, 0.2); }
body.phase-betting #btnBet { box-shadow: 0 0 12px rgba(122, 168, 255, 0.35); }

body.phase-player #btnHit,
body.phase-player #btnStand { box-shadow: 0 0 10px rgba(140, 255, 178, 0.25); }

body.phase-settled #btnBet { border-color: var(--good); background: rgba(140, 255, 178, 0.15); }

/* -------------------------------------------------------------------------
   Layout: table dominant; page scrolls so player cards are never clipped
   ------------------------------------------------------------------------- */
body.page-blackjack {
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
body.page-blackjack #app {
  display: flex;
  flex-direction: column;
  max-width: min(980px, 92vw);
  width: 100%;
  min-height: 100%;
  padding: 6px 12px 8px;
  margin: 0 auto;
  overflow: visible;
  box-sizing: border-box;
}
body.page-blackjack .topbar { flex-shrink: 0; }
body.page-blackjack .netbar { flex-shrink: 0; }
body.page-blackjack .game-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
body.page-blackjack .game-layout .card.panel:first-of-type { flex-shrink: 0; padding: 8px 12px; }
body.page-blackjack .game-layout .bj-table.bj-felt { flex: 1 1 auto; min-height: 320px; width: 100%; }
/* History hidden so player cards don't overlap and layout is cleaner */
body.page-blackjack .game-layout .bj-history-section {
  display: none !important;
}
body.page-blackjack .bj-history-section.collapsed .bj-history { display: none; }
body.page-blackjack .bj-history-section .row { margin-bottom: 4px; }
body.page-blackjack .bj-history-section .title { font-size: 12px; }
body.page-blackjack .bj-history {
  max-height: 52px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}
body.page-blackjack .bj-hitem {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
body.page-blackjack .bj-hitem .t { margin-right: 6px; opacity: 0.85; }
body.page-blackjack .bj-hitem.win { background: rgba(140, 255, 178, 0.15); border: 1px solid rgba(140, 255, 178, 0.3); }
body.page-blackjack .bj-hitem.lose { background: rgba(255, 122, 140, 0.12); border: 1px solid rgba(255, 122, 140, 0.25); }
body.page-blackjack .bj-hitem.push { background: rgba(255, 211, 122, 0.12); border: 1px solid rgba(255, 211, 122, 0.25); }
body.page-blackjack .game-layout .bj-actions { flex-shrink: 0; padding: 8px 12px; }
body.page-blackjack .bj-controls-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
body.page-blackjack .bj-controls-row .btn,
body.page-blackjack .bj-controls-row .ghost {
  flex-shrink: 0;
  min-height: 40px;
}
body.page-blackjack .bj-bet-pill { flex-shrink: 0; }
body.page-blackjack .bj-bet-input { width: 72px; text-align: center; }

/* Collapse toggle for history */
.bj-history-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 8px;
}
.bj-history-toggle:hover { color: var(--text); background: rgba(255,255,255,0.06); }

/* Balance sparkle */
.bal-sparkle.bal-win { animation: bal-sparkle 0.8s ease-out; }
.bal-sparkle.bal-lose { animation: bal-sparkle 0.8s ease-out; }
.bal-sparkle.bal-push { animation: bal-sparkle 0.8s ease-out; }
@keyframes bal-sparkle {
  from { box-shadow: 0 0 0 0 rgba(140, 255, 178, 0.4); }
  to { box-shadow: 0 0 0 8px rgba(140, 255, 178, 0); }
}

/* Score bump */
.bj-score.bump { animation: bj-bump 0.18s ease-out; }
@keyframes bj-bump {
  from { transform: scale(1.1); }
  to { transform: scale(1); }
}

/* Split hands */
.bj-split-wrap { display: flex; gap: 12px; flex-wrap: wrap; }
.bj-split-hand { padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,0.2); }
.bj-split-hand.active { border-color: rgba(140, 255, 178, 0.4); background: rgba(140, 255, 178, 0.08); }
.bj-split-hand.pulse { animation: pulse 0.52s ease-out; }
.bj-split-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 12px; }
.bj-split-hand .bj-cards { min-height: 72px; }

/* Select styling */
body.page-blackjack .select {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
}

/* -------------------------------------------------------------------------
   Mobile — scrollable layout so player cards are always visible
   ------------------------------------------------------------------------- */
@media (max-width: 640px) {
  body.page-blackjack {
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 100vh;
  }
  body.page-blackjack #app {
    overflow: visible;
    min-height: 100%;
  }
  body.page-blackjack .game-layout { gap: 6px; flex: 0 0 auto; }
  body.page-blackjack .bj-table.bj-felt { min-height: 140px; flex: 0 0 auto; }
  .bj-zone { padding: 10px 12px 14px; flex-shrink: 0; }
  .bj-hand:first-of-type { flex-shrink: 0; }
  .bj-hand:last-of-type { flex-shrink: 0; }
  .bj-card { width: 52px; height: 72px; min-width: 52px; min-height: 72px; }
  .bj-card .r { font-size: 14px; }
  .bj-card .s { font-size: 16px; }
  .bj-cards { min-height: 72px; gap: 6px; }
  .bj-chips .bj-chip-btn { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  body.page-blackjack .bj-controls-row { flex-wrap: wrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  body.page-blackjack .bj-controls-row .btn,
  body.page-blackjack .bj-controls-row .ghost { min-height: 44px; min-width: 44px; padding: 10px 14px; }
  .bj-status { font-size: 12px; padding: 6px 12px; }
}

@media (max-width: 420px) {
  .bj-shoe { width: 44px; height: 34px; top: 8px; right: 10px; }
  .bj-discard { width: 40px; height: 30px; bottom: 8px; right: 10px; }
}
