* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 30%, #1a6b3c 0%, #14532d 55%, #0b3a1e 100%);
  color: #f0fdf4;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
}

.screen.active {
  display: flex;
}

.hidden { display: none !important; }

.title {
  font-size: 2.6rem;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

.subtitle {
  color: #bbf7d0;
  margin-top: -10px;
}

.field {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: #bbf7d0;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.15rem;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  outline: none;
  text-align: center;
}

.field input:focus {
  border-color: #fbbf24;
}

#input-code { text-transform: uppercase; letter-spacing: 0.4em; }

.btn {
  width: 100%;
  padding: 15px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

.btn:active { transform: scale(0.97); filter: brightness(0.9); }

.btn-primary {
  background: linear-gradient(180deg, #fbbf24, #d97706);
  color: #451a03;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-ghost {
  background: transparent;
  color: #bbf7d0;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  font-weight: 500;
  font-size: 0.95rem;
}

.divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #86efac;
  font-size: 0.85rem;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
}

.error {
  color: #fca5a5;
  font-weight: 600;
  text-align: center;
}

.room-code {
  font-size: 3.4rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  padding: 14px 24px 14px 38px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 18px;
  border: 2px dashed rgba(251, 191, 36, 0.6);
  color: #fbbf24;
}

.hint { color: #bbf7d0; text-align: center; font-size: 0.95rem; }

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fbbf24;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- juego ---- */

.vs-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.15rem;
  font-weight: 700;
}

.vs { color: #86efac; font-size: 0.85rem; font-weight: 400; }
.player-you { color: #fbbf24; }
.player-opp { color: #93c5fd; }

#cup-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.cup {
  position: relative;
  width: 110px;
  height: 130px;
  animation: wiggle 2.2s ease-in-out infinite;
}

.cup.shaking { animation: shake 0.35s ease-in-out infinite; }

/* mientras el acelerómetro mueve el cubilete, manda el transform inline */
.cup.jitter { animation: none; }

/* el cubilete se levanta y se da vuelta para volcar los dados */
.cup.throwing { animation: throw 0.7s ease-in-out forwards; }

@keyframes throw {
  0% { transform: rotate(0); }
  30% { transform: translateY(-36px) rotate(-20deg); }
  60% { transform: translateY(-14px) rotate(-140deg); }
  100% { transform: translateY(-14px) rotate(-140deg); }
}

.cup-body {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #92400e, #78350f);
  clip-path: polygon(8% 0, 92% 0, 78% 100%, 22% 100%);
  border-radius: 8px;
  box-shadow: inset 0 -12px 20px rgba(0, 0, 0, 0.4);
}

.cup-rim {
  position: absolute;
  top: -7px;
  left: 2%;
  width: 96%;
  height: 16px;
  background: linear-gradient(180deg, #b45309, #92400e);
  border-radius: 50%;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

@keyframes shake {
  0%, 100% { transform: rotate(-14deg) translateY(-4px); }
  50% { transform: rotate(14deg) translateY(4px); }
}

.instruction {
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ---- dados ---- */

.dice-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.die {
  width: 56px;
  height: 56px;
  background: linear-gradient(145deg, #ffffff, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 -3px 6px rgba(0, 0, 0, 0.12);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 8px;
}

.dice-row.small .die {
  width: 44px;
  height: 44px;
  padding: 6px;
  border-radius: 10px;
}

.die.rolling { animation: tumble 0.45s ease-in-out infinite; }

/* dado volando desde el cubilete hasta su lugar */
.die.fly {
  position: fixed;
  margin: 0;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
}

/* pique al aterrizar */
.die.land { animation: land 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }

@keyframes land {
  0% { transform: translateY(-16px) scale(1.18); }
  60% { transform: translateY(3px) scale(0.94); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes tumble {
  0% { transform: rotate(0) translateY(0); }
  25% { transform: rotate(12deg) translateY(-8px); }
  50% { transform: rotate(-8deg) translateY(0); }
  75% { transform: rotate(6deg) translateY(-4px); }
  100% { transform: rotate(0) translateY(0); }
}

.pip {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pip::after {
  content: '';
  width: 72%;
  height: 72%;
  max-width: 12px;
  max-height: 12px;
  border-radius: 50%;
  background: #1e293b;
}

.pip.off::after { display: none; }

.total {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fbbf24;
  text-align: center;
}

#dice-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: 100%;
}

.opp-status {
  color: #93c5fd;
  font-weight: 600;
}

/* ---- resultado ---- */

.winner-banner {
  font-size: 1.7rem;
  font-weight: 800;
  text-align: center;
  padding: 18px 22px;
  border-radius: 18px;
  width: 100%;
}

.winner-banner.win {
  background: linear-gradient(180deg, #fbbf24, #d97706);
  color: #451a03;
  animation: winner-pop 0.5s ease;
}

.winner-banner.lose {
  background: rgba(0, 0, 0, 0.35);
  color: #fca5a5;
}

.winner-banner.tie {
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

@keyframes winner-pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.result-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 16px;
}

.result-name { font-weight: 700; color: #bbf7d0; }

/* ---- apuestas (dudo) ---- */

.special-banner {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fde68a;
  font-size: 0.88rem;
  text-align: center;
}

.bid-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.current-bid {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fbbf24;
  text-align: center;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  width: 100%;
}

.turn-status {
  font-weight: 700;
  color: #bbf7d0;
}

.bid-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.btn-round {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  font-size: 1.7rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
}

.btn-round:active { transform: scale(0.92); }

.bid-qty {
  font-size: 2.2rem;
  font-weight: 800;
  color: #fbbf24;
  min-width: 54px;
  text-align: center;
}

.pinta-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.pinta-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: #e2e8f0;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.pinta-btn.selected {
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.18);
  color: #fde68a;
}

.pinta-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.die.mini {
  width: 30px;
  height: 30px;
  padding: 4px;
  border-radius: 7px;
  pointer-events: none;
}

.die.mini .pip::after { max-width: 5px; max-height: 5px; }

.action-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.action-row .btn { padding: 12px 6px; font-size: 1rem; }

.btn-danger {
  background: linear-gradient(180deg, #ef4444, #b91c1c);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
  filter: none;
}

/* ---- dados especiales ---- */

.die.unknown {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #64748b;
  background: linear-gradient(145deg, #cbd5e1, #94a3b8);
}

.die.hit {
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.7);
}

/* ---- pantallas nuevas ---- */

.starter-row {
  display: flex;
  gap: 14px;
  width: 100%;
  justify-content: center;
}

.starter-row .result-block { flex: 1; }

.reveal-outcome {
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
}

#obligar-choice, #obligar-wait {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  width: 100%;
}

#obligar-choice .btn small {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  margin-top: 4px;
  opacity: 0.85;
}

/* ---- ta-te-ti ---- */

.tt-grid {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 10px;
  width: min(88vw, 340px);
  aspect-ratio: 1;
}

.tt-cell {
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.3s, transform 0.12s;
}

.tt-cell:active { transform: scale(0.94); }

.mark-x { color: #fbbf24; text-shadow: 0 0 12px rgba(251, 191, 36, 0.4); }
.mark-o { color: #93c5fd; text-shadow: 0 0 12px rgba(147, 197, 253, 0.4); }

/* la ficha más vieja del jugador en turno: está por desaparecer */
.tt-cell.fading { opacity: 0.35; }

.tt-cell.win-cell {
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.16);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.65);
}

.tt-cell.pop { animation: tt-pop 0.25s ease; }

@keyframes tt-pop {
  0% { transform: scale(0.4); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.round-end {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-link {
  color: #86efac;
  font-size: 0.9rem;
  margin-top: 8px;
}

/* ---- snake ---- */

.snake-wrap {
  position: relative;
}

#board {
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  touch-action: none;
  display: block;
}

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.5rem;
  font-weight: 800;
  color: #fbbf24;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* ---- batalla naval ---- */

.nv-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  width: min(88vw, 350px);
  aspect-ratio: 1;
}

.nv-grid.small { width: min(50vw, 200px); }

.nv-grid.enemy .nv-cell { cursor: pointer; }

.nv-cell {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 3px;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.nv-cell.ship { background: #94a3b8; }

.nv-cell.ship.sel {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.7);
}

.nv-cell.agua::after {
  content: '';
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: #38bdf8;
}

.nv-cell.tocado { background: #ef4444; }
.nv-cell.ship.tocado { background: #b91c1c; }

.nv-cell.hundido {
  background: #7f1d1d;
  border-color: #ef4444;
}

.nv-label {
  color: #bbf7d0;
  font-size: 0.85rem;
  font-weight: 600;
  width: 100%;
  text-align: left;
}

/* ---- menú principal ---- */

.menu-screen { gap: 22px; }

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
}

.menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 12px 16px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  text-decoration: none;
  color: #f0fdf4;
  transition: transform 0.12s, border-color 0.15s;
}

.menu-card:active {
  transform: scale(0.96);
  border-color: #fbbf24;
}

.menu-art {
  font-size: 3rem;
  line-height: 1;
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-art img {
  max-width: 100%;
  max-height: 100%;
}

.menu-name {
  font-size: 1.15rem;
  font-weight: 800;
}

.menu-tag {
  font-size: 0.78rem;
  color: #bbf7d0;
  text-align: center;
}

.menu-foot {
  color: #86efac;
  font-size: 0.85rem;
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fca5a5;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 12px;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
