:root {
  --bg: #0d0b1a;
  --bg-2: #15122a;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f5f3ff;
  --muted: #a7a3c2;
  --pink: #ff3d7f;
  --violet: #8b5cf6;
  --cyan: #22d3ee;
  --lime: #a3e635;
  --yellow: #facc15;
  --orange: #fb923c;
  --red: #ef4444;
  --radius: 20px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
p { margin: 0; }

/* Fondo animado */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-blobs span {
  position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  filter: blur(90px); opacity: 0.28; animation: float 22s ease-in-out infinite alternate;
}
.bg-blobs span:nth-child(1) { background: var(--violet); top: -25vmax; left: -20vmax; }
.bg-blobs span:nth-child(2) { background: var(--pink); bottom: -30vmax; right: -25vmax; animation-delay: -7s; }
.bg-blobs span:nth-child(3) { background: var(--cyan); top: 40%; left: 50%; width: 35vmax; height: 35vmax; opacity: 0.14; animation-delay: -14s; }
@keyframes float { to { transform: translate(8vmax, 6vmax) scale(1.1); } }

#app { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 28px 0 22px; }
.logo { font-family: var(--font-display); font-weight: 800; font-size: clamp(2.6rem, 11vw, 4.2rem); letter-spacing: -0.04em; }
.logo .grad {
  background: linear-gradient(90deg, var(--pink), var(--violet), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--muted); margin-top: 6px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.panel + .panel { margin-top: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { font-size: 1.2rem; }
.hint { color: var(--muted); font-size: 0.88rem; }

.add-row { display: flex; gap: 8px; }
.input {
  flex: 1; min-width: 0; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px; outline: none; transition: border-color .2s;
}
.input:focus { border-color: var(--violet); }
textarea.input { resize: vertical; min-height: 80px; width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 8px 7px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: 0.92rem;
  animation: pop .25s ease;
}
.chip .x { border: 0; background: rgba(255,255,255,.12); width: 22px; height: 22px; border-radius: 50%; line-height: 1; padding: 0; font-size: 0.8rem; }
.chip .badge { font-size: 0.75rem; background: var(--pink); color: #fff; padding: 1px 7px; border-radius: 999px; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: rgba(255,255,255,.15); border-radius: 999px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--lime); }
.switch input:checked + span::before { transform: translateX(20px); }

.section-title { font-size: 1.35rem; margin: 28px 4px 12px; }
.games-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.game-card {
  position: relative; text-align: left; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; min-height: 150px; overflow: hidden; background: var(--bg-2);
  display: flex; flex-direction: column; gap: 6px; transition: transform .15s ease, box-shadow .2s;
}
.game-card::before { content: ""; position: absolute; inset: 0; background: var(--g); opacity: .85; z-index: 0; }
.game-card > * { position: relative; z-index: 1; }
.game-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.game-card:active { transform: scale(.98); }
.game-card .emoji { font-size: 2.2rem; line-height: 1; filter: drop-shadow(0 4px 8px rgba(0,0,0,.3)); }
.game-card h3 { font-size: 1.3rem; margin-top: 6px; }
.game-card p { font-size: 0.88rem; color: rgba(255,255,255,.85); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 8px; }
.tag { font-size: 0.72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: rgba(0,0,0,.28); text-transform: uppercase; letter-spacing: .04em; }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 36px; }

/* ---------- Pantalla de juego ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 4px 0 16px; position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 1.35rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; font-size: 1.2rem; flex: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.center { text-align: center; }
.big-title { font-size: clamp(1.8rem, 8vw, 2.6rem); }
.lead { font-size: 1.1rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 16px; padding: 15px 20px; font-weight: 700; font-size: 1.02rem;
  background: var(--surface-2); border: 1px solid var(--border); transition: transform .1s, filter .2s;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, var(--pink), var(--violet)); border-color: transparent; box-shadow: 0 8px 24px rgba(255, 61, 127, .3); }
.btn.cyan { background: linear-gradient(135deg, var(--cyan), #3b82f6); border-color: transparent; color: #04111c; }
.btn.lime { background: linear-gradient(135deg, var(--lime), #22c55e); border-color: transparent; color: #0b1a05; }
.btn.danger { background: linear-gradient(135deg, var(--red), var(--orange)); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.xl { padding: 20px; font-size: 1.2rem; border-radius: 20px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > label, .label { font-weight: 600; font-size: 0.95rem; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-weight: 600; font-size: 0.9rem; transition: .15s;
}
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.stepper { display: inline-flex; align-items: center; gap: 4px; background: rgba(0,0,0,.3); border: 1px solid var(--border); border-radius: 16px; padding: 4px; }
.stepper button { width: 42px; height: 42px; border-radius: 12px; border: 0; background: var(--surface-2); font-size: 1.3rem; font-weight: 700; }
.stepper output { min-width: 44px; text-align: center; font-weight: 800; font-size: 1.2rem; font-family: var(--font-display); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Carta grande central */
.card-big {
  position: relative; border-radius: 28px; padding: 32px 22px; min-height: 260px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center;
  background: linear-gradient(160deg, rgba(139, 92, 246, .35), rgba(255, 61, 127, .25)); border: 1px solid var(--border);
  box-shadow: var(--shadow); animation: cardIn .35s cubic-bezier(.2, .9, .3, 1.3);
}
.card-big .kicker { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .14em; font-weight: 700; color: rgba(255,255,255,.7); }
.card-big .text { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.5rem, 6.5vw, 2.2rem); line-height: 1.15; }
.card-big .emoji { font-size: 3.4rem; line-height: 1; }
.card-big.danger { background: linear-gradient(160deg, rgba(239, 68, 68, .5), rgba(251, 146, 60, .3)); }
.card-big.good { background: linear-gradient(160deg, rgba(163, 230, 53, .35), rgba(34, 211, 238, .25)); }
.card-big.cyan { background: linear-gradient(160deg, rgba(34, 211, 238, .35), rgba(59, 130, 246, .3)); }
@keyframes cardIn { from { transform: translateY(18px) scale(.94) rotate(-1deg); opacity: 0; } }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 700; font-size: 0.9rem; }
.pill.pink { background: rgba(255, 61, 127, .2); border-color: rgba(255, 61, 127, .5); }

/* Lista de jugadores seleccionables */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); gap: 8px; }
.pbtn {
  padding: 14px 10px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface);
  font-weight: 700; text-align: center; transition: .15s; position: relative;
}
.pbtn.on { background: linear-gradient(135deg, var(--pink), var(--violet)); border-color: transparent; }
.pbtn.dead { opacity: .45; text-decoration: line-through; }
.pbtn .sub { display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); }

/* Revelado privado */
.reveal-screen { min-height: 60dvh; display: flex; flex-direction: column; justify-content: center; gap: 18px; text-align: center; }
.reveal-name { font-family: var(--font-display); font-weight: 800; font-size: clamp(2.2rem, 11vw, 3.6rem); background: linear-gradient(90deg, var(--yellow), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; overflow-wrap: anywhere; }
.progress-dots { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.progress-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); }
.progress-dots i.done { background: var(--lime); }
.progress-dots i.now { background: var(--pink); transform: scale(1.4); }

/* Tabla / marcador */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.list-item.win { border-color: var(--lime); background: rgba(163, 230, 53, .12); }
.list-item.lose { border-color: rgba(239, 68, 68, .5); background: rgba(239, 68, 68, .1); }
.list-item b { font-family: var(--font-display); font-size: 1.15rem; }

/* Naipes */
.cards-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 92px; }
.pcard {
  width: 60px; height: 88px; border-radius: 10px; background: #fff; color: #111; display: flex; flex-direction: column;
  justify-content: space-between; padding: 6px 7px; font-weight: 800; font-family: var(--font-display);
  box-shadow: 0 6px 14px rgba(0,0,0,.4); animation: deal .35s cubic-bezier(.2,.9,.3,1.3);
}
.pcard.red { color: #e11d48; }
.pcard .c { font-size: 1.6rem; text-align: center; line-height: 1; }
.pcard .r { font-size: 1rem; line-height: 1; }
.pcard .r.b { align-self: flex-end; transform: rotate(180deg); }
.pcard.lg { width: 120px; height: 170px; border-radius: 16px; padding: 10px 12px; }
.pcard.lg .c { font-size: 3.4rem; }
.pcard.lg .r { font-size: 1.6rem; }
@keyframes deal { from { transform: translateY(-40px) rotate(-12deg); opacity: 0; } }

.hidden-card { perspective: 900px; width: 130px; height: 180px; margin: 0 auto; }
.hidden-card .inner { position: relative; width: 100%; height: 100%; transition: transform .8s cubic-bezier(.3,.7,.3,1.2); transform-style: preserve-3d; }
.hidden-card.flipped .inner { transform: rotateY(180deg); }
.hidden-card .face { position: absolute; inset: 0; border-radius: 18px; display: grid; place-items: center; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: var(--shadow); }
.hidden-card .back { background: repeating-linear-gradient(45deg, var(--pink) 0 10px, var(--violet) 10px 20px); border: 5px solid #fff; font-size: 3rem; }
.hidden-card .front { background: #fff; color: #111; transform: rotateY(180deg); font-family: var(--font-display); font-weight: 800; font-size: 4.5rem; }

.team-box { border-radius: 18px; padding: 14px; border: 2px solid var(--border); background: var(--surface); transition: .2s; }
.team-box.active { border-color: var(--yellow); box-shadow: 0 0 0 4px rgba(250, 204, 21, .15); }
.team-box.out { opacity: .6; }
.team-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.team-head h3 { font-size: 1.15rem; }
.sum { font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; }

/* Bomba */
.bomb { font-size: 8rem; line-height: 1; text-align: center; animation: tick 1s ease-in-out infinite; user-select: none; }
@keyframes tick { 50% { transform: scale(1.08) rotate(-4deg); } }
.boom { animation: boom .6s ease; }
@keyframes boom { 0% { transform: scale(.3); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
.flash { position: fixed; inset: 0; background: #fff; z-index: 50; pointer-events: none; animation: flash .7s ease forwards; }
@keyframes flash { to { opacity: 0; } }

/* Ruleta */
.wheel-wrap { position: relative; width: min(86vw, 360px); aspect-ratio: 1; margin: 6px auto 0; }
.wheel-wrap canvas { width: 100%; height: 100%; border-radius: 50%; box-shadow: 0 0 0 6px rgba(255,255,255,.12), var(--shadow); transition: transform 4.5s cubic-bezier(.12,.75,.12,1); }
.wheel-pointer { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid #fff; filter: drop-shadow(0 3px 4px rgba(0,0,0,.5)); z-index: 2; }

/* Timer */
.timer { font-family: var(--font-display); font-weight: 800; font-size: 3rem; text-align: center; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--red); animation: tick .5s infinite; }
.countdown-num { font-family: var(--font-display); font-weight: 800; font-size: 7rem; text-align: center; animation: boom .5s ease; }

/* Toasts */
#toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 420px); pointer-events: none; }
.toast { background: rgba(20, 16, 40, .95); border: 1px solid var(--border); padding: 12px 16px; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow); animation: toastIn .3s ease; text-align: center; }
.toast.out { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(20px); opacity: 0; } }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(5, 3, 15, .7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--bg-2); border: 1px solid var(--border); border-radius: 24px; padding: 22px; width: min(100%, 560px); max-height: 85dvh; overflow: auto; animation: cardIn .3s ease; }
.modal-box h2 { font-size: 1.5rem; margin-bottom: 12px; }
.modal-box ul, .modal-box ol { padding-left: 20px; margin: 8px 0; }
.modal-box li { margin: 6px 0; }
.modal-box p { margin: 8px 0; }
@media (min-width: 640px) { .modal { align-items: center; } }

.fade-in { animation: cardIn .3s ease; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.scoreboard { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Multi-página ---------- */
a.game-card, a.icon-btn { color: inherit; text-decoration: none; }

/* Ranking de la noche */
.ranking { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.rank-row { display: grid; grid-template-columns: minmax(0, 7.5rem) 1fr auto; align-items: center; gap: 10px; font-size: 0.92rem; }
.rank-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.rank-bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,.08); overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--pink), var(--yellow)); transition: width .6s ease; }
.rank-row b { font-family: var(--font-display); min-width: 2ch; text-align: right; }
