/* ============================================================
   Blackjack Royale — estilos
   ============================================================ */
@property --ang {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

:root {
  --gold: #e8c25a;
  --gold-light: #f7dc83;
  --gold-dark: #a97a22;
  --red: #c8102e;
  --text: #f5f1e6;
  --cw: clamp(56px, min(8.5vw, 11vh), 96px);
  --ch: calc(var(--cw) * 1.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Poppins', system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 30%, #154a32 0%, #071a12 55%, #020604 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- Fondo animado ---------- */
#bg-suits { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
#bg-suits span {
  position: absolute;
  bottom: -80px;
  font-size: var(--s);
  color: rgba(232, 194, 90, 0.07);
  animation: floatUp var(--d) linear var(--delay) infinite;
}
@keyframes floatUp {
  to { transform: translateY(-120vh) rotate(360deg); }
}

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

#flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 55; opacity: 0;
  background: radial-gradient(circle at 50% 50%, rgba(247, 220, 131, 0.55), transparent 65%);
}
#flash.on { animation: flash 0.9s ease-out; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Toast ---------- */
#toast {
  position: fixed; top: 22px; left: 50%; z-index: 70;
  transform: translate(-50%, calc(-100% - 40px));
  opacity: 0;
  padding: 12px 24px; border-radius: 999px;
  background: rgba(10, 20, 15, 0.8);
  border: 1px solid rgba(232, 194, 90, 0.5);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.95rem;
  transition: transform 0.45s cubic-bezier(0.2, 1.2, 0.3, 1), opacity 0.3s;
  max-width: 92vw;
  text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Pantallas ---------- */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  perspective: 1200px;
  opacity: 0; visibility: hidden;
  transform: scale(1.04);
  transition: opacity 0.6s ease, transform 0.6s ease, visibility 0.6s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; }

/* ---------- Panel de vidrio ---------- */
.panel {
  position: relative;
  width: min(420px, 100%);
  padding: 40px 36px 36px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(232, 194, 90, 0.25);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transform-style: preserve-3d;
  transition: transform 0.25s ease-out;
}
/* borde dorado giratorio */
.panel::before {
  content: '';
  position: absolute; inset: -1px;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(from var(--ang), transparent 0 65%, var(--gold-light) 78%, var(--gold) 82%, transparent 92%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  animation: spin 5s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { --ang: 360deg; } }

.hero {
  position: relative;
  height: calc(var(--ch) * 0.9);
  margin: -110px auto 18px;
  width: 200px;
}
.hero .card {
  position: absolute; left: 50%; top: 0;
  animation: heroFloat 4s ease-in-out infinite;
}
.hero .card:nth-child(1) { --r: -14deg; --x: -78%; }
.hero .card:nth-child(2) { --r: 12deg; --x: -22%; animation-delay: -2s; }
@keyframes heroFloat {
  0%, 100% { transform: translateX(var(--x)) rotate(var(--r)) translateY(0); }
  50% { transform: translateX(var(--x)) rotate(var(--r)) translateY(-10px); }
}

.logo {
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: clamp(2.6rem, 9vw, 3.6rem);
  letter-spacing: 0.05em;
  background: linear-gradient(100deg, #a97a22 0%, #f7dc83 25%, #fffbe8 38%, #e8c25a 52%, #a97a22 75%, #f7dc83 100%);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 5s ease-in-out infinite alternate;
  filter: drop-shadow(0 4px 18px rgba(232, 194, 90, 0.35));
}
@keyframes shimmer { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }

.tagline {
  margin: 4px 0 30px;
  font-family: 'Cinzel', serif;
  letter-spacing: 0.35em;
  font-size: 0.8rem;
  color: rgba(232, 194, 90, 0.75);
}

.btn-col { display: flex; flex-direction: column; gap: 14px; }

.title { font-family: 'Cinzel', serif; font-size: 2rem; color: var(--gold); letter-spacing: 0.06em; }
.sub { margin-top: 6px; color: rgba(245, 241, 230, 0.65); font-size: 0.92rem; }

.back {
  position: absolute; top: 16px; left: 18px;
  background: none; border: none; cursor: pointer;
  color: rgba(245, 241, 230, 0.6); font-size: 0.85rem;
  transition: color 0.2s;
}
.back:hover { color: var(--gold); }

/* ---------- Botones ---------- */
.btn {
  position: relative; overflow: hidden;
  font-weight: 600; font-size: 1rem; letter-spacing: 0.04em;
  padding: 14px 30px;
  border-radius: 999px;
  border: 1px solid rgba(232, 194, 90, 0.5);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.25s, background 0.25s, opacity 0.2s;
}
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4), 0 0 22px rgba(232, 194, 90, 0.25);
}
.btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.gold {
  background: linear-gradient(180deg, #f9e39a, #d9ae45 55%, #a97a22);
  color: #2a1a04;
  border-color: #f7e3a1;
  box-shadow: 0 6px 20px rgba(212, 168, 60, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.btn.gold:hover:not(:disabled) { background: linear-gradient(180deg, #fff0b8, #e6bb52 55%, #b8862b); }
.btn::after {
  content: '';
  position: absolute; top: 0; left: -80%;
  width: 50%; height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: skewX(-20deg);
  transition: left 0.6s;
}
.btn:hover:not(:disabled)::after { left: 140%; }
.btn.small { padding: 8px 18px; font-size: 0.85rem; }
.btn.wide { width: 100%; }

/* ---------- Campo DNI ---------- */
.field { position: relative; margin: 28px 0 6px; }
.field input {
  width: 100%;
  padding: 22px 18px 10px;
  font: 600 1.5rem 'Poppins', sans-serif;
  letter-spacing: 0.3em;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(232, 194, 90, 0.35);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.25s;
}
.field input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(232, 194, 90, 0.15), 0 0 28px rgba(232, 194, 90, 0.22);
}
.field label {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(245, 241, 230, 0.5);
  letter-spacing: 0.15em;
  pointer-events: none;
  transition: all 0.2s ease;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label {
  top: 12px; font-size: 0.7rem; color: var(--gold);
}
.field + .field { margin-top: 16px; }
.field.text input { font-size: 1.05rem; letter-spacing: 0.02em; }

.btn.loading { pointer-events: none; }
.btn.loading::before {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 10px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: rot 0.7s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

.error { min-height: 1.4em; margin-bottom: 14px; color: #ff8a8a; font-size: 0.85rem; }

.shake { animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ============================================================
   Mesa
   ============================================================ */
#screen-game {
  flex-direction: column; align-items: stretch; justify-content: flex-start;
  gap: 14px; padding: 14px 20px 18px;
  overflow-y: auto;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 18px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(232, 194, 90, 0.2);
  backdrop-filter: blur(8px);
}
.player { font-size: 0.9rem; color: rgba(245, 241, 230, 0.75); }
.player strong { color: var(--text); letter-spacing: 0.05em; }
.brand { font-family: 'Cinzel', serif; color: var(--gold); letter-spacing: 0.12em; }
.right { display: flex; align-items: center; gap: 16px; }
.balance { font-size: 0.9rem; color: rgba(245, 241, 230, 0.75); }
.balance strong { display: inline-block; margin-left: 6px; color: var(--gold); font-size: 1.25rem; }
.balance strong.gain { animation: gain 0.7s ease; }
@keyframes gain {
  40% { transform: scale(1.25); color: #fff6c9; text-shadow: 0 0 18px rgba(247, 220, 131, 0.9); }
}

.rail {
  flex: 1; min-height: 0;
  padding: 14px;
  border-radius: 40px 40px 50% 50% / 40px 40px 34% 34%;
  background: linear-gradient(180deg, #5a3519, #3a200e 60%, #2a1709);
  box-shadow: 0 0 0 2px var(--gold-dark), 0 25px 60px rgba(0, 0, 0, 0.7), inset 0 2px 0 rgba(255, 255, 255, 0.15);
  display: flex;
}
.felt {
  position: relative; flex: 1;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: 22px 20px 40px;
  border-radius: 28px 28px 50% 50% / 28px 28px 33% 33%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.09'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 38%, #1d9560 0%, #0f6b43 45%, #06402a 100%);
  box-shadow: inset 0 0 0 2px rgba(232, 194, 90, 0.35), inset 0 0 120px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.felt::before {
  content: '';
  position: absolute; inset: 16px;
  border-radius: inherit;
  border: 2px solid rgba(232, 194, 90, 0.18);
  pointer-events: none;
}

.shoe { position: absolute; top: 22px; right: 28px; width: calc(var(--cw) * 0.8); height: calc(var(--ch) * 0.8); }
.shoe i {
  position: absolute; inset: 0;
  border-radius: 8px;
  background: repeating-linear-gradient(45deg, #7a0f22 0 5px, #5c0a19 5px 10px);
  border: 3px solid #f4ead2;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}
.shoe i:nth-child(1) { transform: translate(6px, 6px) rotate(6deg); }
.shoe i:nth-child(2) { transform: translate(3px, 3px) rotate(3deg); }

.hand-area { display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 1; }
.hand-label {
  font-family: 'Cinzel', serif; letter-spacing: 0.12em; font-size: 0.9rem;
  color: rgba(245, 241, 230, 0.8);
  display: flex; align-items: center; gap: 8px;
}
.score {
  min-width: 38px; padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(232, 194, 90, 0.45);
  color: var(--gold);
  font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 0.9rem;
  text-align: center;
}
.score:empty { display: none; }
.score.bump { animation: bump 0.35s ease; }
@keyframes bump { 50% { transform: scale(1.3); } }

.hand { display: flex; justify-content: center; min-height: var(--ch); }
.hand .card + .card { margin-left: calc(var(--cw) * -0.38); }

/* ---------- Cartas ---------- */
.card {
  position: relative; flex-shrink: 0;
  width: var(--cw); height: var(--ch);
  perspective: 900px;
  animation: dealIn 0.5s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}
@keyframes dealIn {
  from { transform: translate(var(--fx, 60vw), var(--fy, -60vh)) rotate(-30deg) scale(0.75); opacity: 0; }
  30% { opacity: 1; }
  to { transform: none; opacity: 1; }
}
.card.leave { animation: leave 0.4s ease-in forwards; }
@keyframes leave { to { transform: translate(-50vw, -30vh) rotate(-50deg) scale(0.7); opacity: 0; } }

.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.3, 1);
}
.card.facedown .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute; inset: 0;
  border-radius: calc(var(--cw) * 0.1);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.4s;
}
.card-front {
  background: linear-gradient(145deg, #ffffff, #f0eadc);
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: #161616;
}
.card-front.red { color: var(--red); }
.card-back {
  transform: rotateY(180deg);
  border: 4px solid #f4ead2;
  background:
    radial-gradient(circle at 50% 50%, rgba(232, 194, 90, 0.35) 0 22%, transparent 23%),
    repeating-linear-gradient(45deg, #7a0f22 0 6px, #5c0a19 6px 12px);
}
.card-back::after {
  content: '♠';
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--gold-light);
  font-size: calc(var(--cw) * 0.32);
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
}

.corner {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  line-height: 1;
  font-size: calc(var(--cw) * 0.16);
}
.corner b { font-size: calc(var(--cw) * 0.21); font-weight: 700; }
.corner.tl { top: 6%; left: 8%; }
.corner.br { bottom: 6%; right: 8%; transform: rotate(180deg); }
.pip {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: calc(var(--cw) * 0.48);
}
.pip.ace { font-size: calc(var(--cw) * 0.62); }
.face {
  display: grid; place-items: center;
  width: 54%; height: 58%;
  font-family: 'Cinzel', serif; font-weight: 800;
  font-size: calc(var(--cw) * 0.36);
  border: 2px solid currentColor;
  border-radius: 6px;
  background: linear-gradient(160deg, rgba(232, 194, 90, 0.35), rgba(232, 194, 90, 0.05));
}

.hand.win .card-front { box-shadow: 0 0 0 2px var(--gold-light), 0 0 28px rgba(247, 220, 131, 0.85); }
.hand.lose { animation: shake 0.5s; }
.hand.lose .card { filter: brightness(0.75) saturate(0.7); transition: filter 0.4s; }

/* ---------- Centro de la mesa ---------- */
.center {
  display: grid; z-index: 1;
  grid-template-columns: auto auto;
  grid-template-areas: 'spot msg' 'amount msg' 'text text';
  align-items: center; justify-items: center;
  column-gap: 26px; row-gap: 4px;
}
.center .message { grid-area: msg; }
.center .bet-spot { grid-area: spot; }
.center .bet-amount { grid-area: amount; }
.center .table-text { grid-area: text; margin-top: 8px; }

.message {
  display: flex; flex-direction: column; align-items: center;
  min-height: 46px;
  padding: 8px 28px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(232, 194, 90, 0.25);
  font-family: 'Cinzel', serif;
  font-size: clamp(1.05rem, 2.4vw, 1.5rem);
  text-align: center;
}
.message small { font-family: 'Poppins', sans-serif; font-size: 0.75rem; opacity: 0.8; }
.message.pop { animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.message.win { color: #ffe9a6; border-color: var(--gold); text-shadow: 0 0 16px rgba(247, 220, 131, 0.8); box-shadow: 0 0 30px rgba(232, 194, 90, 0.35); }
.message.blackjack {
  color: #fff3c4; border-color: var(--gold-light);
  font-size: clamp(1.5rem, 4vw, 2.3rem);
  text-shadow: 0 0 22px rgba(247, 220, 131, 1);
  box-shadow: 0 0 50px rgba(232, 194, 90, 0.55);
}
.message.lose { color: #ffa3a3; border-color: rgba(255, 120, 120, 0.5); }
.message.push { color: #cfe6ff; border-color: rgba(160, 200, 255, 0.5); }

.bet-spot {
  position: relative;
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 2px dashed rgba(232, 194, 90, 0.45);
  display: grid; place-items: center;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.bet-spot.has-bet { border-color: var(--gold); box-shadow: 0 0 24px rgba(232, 194, 90, 0.3); }
.bet-label { font-family: 'Cinzel', serif; font-size: 0.6rem; letter-spacing: 0.15em; color: rgba(232, 194, 90, 0.6); }
.bet-spot.has-bet .bet-label { opacity: 0; }
.bet-stack { position: absolute; inset: 0; }
.bet-amount { font-weight: 700; color: var(--gold); min-height: 1.2em; }
.table-text {
  font-family: 'Cinzel', serif; font-size: 0.68rem; letter-spacing: 0.22em;
  color: rgba(232, 194, 90, 0.45);
  text-align: center;
}

/* ---------- Fichas ---------- */
.chip {
  --c: #2563c9;
  --s: #f5f1e6;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-weight: 700; font-size: 0.95rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  background:
    radial-gradient(circle, var(--c) 0 47%, var(--s) 48% 51%, transparent 52%),
    repeating-conic-gradient(var(--c) 0 20deg, var(--s) 20deg 40deg);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 6px 14px rgba(0, 0, 0, 0.55), inset 0 0 0 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s cubic-bezier(0.2, 1.4, 0.4, 1), box-shadow 0.2s, opacity 0.2s;
}
.chip:hover:not(:disabled) { transform: translateY(-5px) rotate(18deg); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 12px 22px rgba(0, 0, 0, 0.6), 0 0 18px var(--c); }
.chip:active:not(:disabled) { transform: scale(0.92); }
.chip:disabled { opacity: 0.3; cursor: not-allowed; }
.c10 { --c: #2563c9; }
.c25 { --c: #1e8a4c; }
.c50 { --c: #c0283a; }
.c100 { --c: #1b1b1b; --s: #e8c25a; }

.chip.mini {
  position: absolute;
  left: 50%; top: 50%;
  width: 42px; height: 42px;
  font-size: 0;
  transform: translate(-50%, calc(-50% - var(--i) * 4px));
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 4px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.chip.flying { position: fixed; z-index: 65; pointer-events: none; margin: 0; }

.chips { display: flex; gap: 12px; }

/* ---------- Controles ---------- */
.controls { display: flex; justify-content: center; min-height: 72px; }
.bet-controls, .play-controls {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 14px;
}
.play-controls .btn { min-width: 130px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .brand { display: none; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  #screen-game { padding: 10px; gap: 10px; }
  .chip { width: 50px; height: 50px; font-size: 0.8rem; }
  .play-controls .btn { min-width: 0; padding: 12px 20px; }
  .shoe { display: none; }
  .table-text { display: none; }
  .rail { padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
