/* =============================================
   BINGO DE LAS LETRAS — 1º GRADO
   Optimizado para Chromebook 1366×768 landscape
   ============================================= */

:root {
  --green:       #1aad72;
  --green-light: #d4f5e9;
  --green-dark:  #0d7a50;

  --blue:        #3b8eea;
  --blue-light:  #ddeeff;
  --blue-dark:   #1a5cb8;

  --amber:       #f5a623;
  --amber-light: #fff3d4;
  --amber-dark:  #b37400;

  --red:         #e84040;
  --red-light:   #ffe0e0;

  --purple:      #7c5cbf;
  --purple-light:#ede8ff;

  --surface:     #ffffff;
  --bg:          #f5f2ee;
  --border:      #e0d8cc;
  --text:        #2a2520;
  --text-muted:  #7a7268;

  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --radius-xl:   28px;

  --font-display: 'Baloo 2', cursive;
  --font-body:    'Nunito', sans-serif;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* =============================================
   PANTALLA DE SELECCIÓN
   ============================================= */

#setup-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 20%, #d4f5e9 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, #ddeeff 0%, transparent 50%),
    radial-gradient(ellipse at 60% 10%, #fff3d4 0%, transparent 40%),
    var(--bg);
}

.setup-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  max-width: 700px;
  width: 100%;
  text-align: center;
  border: 2px solid var(--border);
}

.setup-logo {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 0.75rem;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

.setup-card h1 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--green-dark);
  margin-bottom: 0.4rem;
}

.setup-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 1.5rem;
}

.player-btn {
  padding: 14px 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
}

.player-btn:hover {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.player-btn.selected {
  background: var(--green);
  border-color: var(--green-dark);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(26,173,114,0.4);
}

.start-btn {
  padding: 16px 48px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 16px rgba(26,173,114,0.35);
}

.start-btn:hover:not(:disabled) {
  background: var(--green-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(26,173,114,0.45);
}

.start-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: default;
  box-shadow: none;
}

/* =============================================
   PANTALLA DE JUEGO — tablero a pantalla completa
   Layout: header | tablero (sin sidebar)
   ============================================= */

#game-screen {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header"
    "board";
  min-height: 100vh;
  height: 100vh;
  gap: 0;
  overflow: hidden;
}

/* ---- TOP BAR ---- */
.top-bar {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 8px 14px;
}

.back-btn {
  padding: 7px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.back-btn:hover {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}

.top-bar h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--green-dark);
}

.topbar-spacer { flex: 1; }

/* ---- ÁREA PRINCIPAL: TABLERO ---- */
.board-area {
  grid-area: board;
  display: flex;
  flex-direction: column;
  padding: 12px 14px 10px;
  gap: 0;
  overflow: hidden;
}

/* ---- CUADRÍCULA DEL BINGO ---- */
/* 9 col × 3 filas, ocupa todo el espacio disponible */
.bingo-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 9px;
  flex: 1;
  min-height: 0;
}

.cell {
  border: 2.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 6px 4px;
  user-select: none;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.cell:hover {
  border-color: var(--green);
  transform: scale(1.04);
  box-shadow: 0 4px 14px rgba(26,173,114,0.25);
  z-index: 1;
}

.cell.marked {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  border-color: var(--green-dark);
  box-shadow: 0 4px 14px rgba(26,173,114,0.4);
}

.cell.marked .cell-word { color: #fff; font-weight: 800; }
.cell.marked .cell-emoji { filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2)); }

.cell.free-space {
  background: linear-gradient(135deg, var(--blue-light) 0%, #c8e8ff 100%);
  border-color: var(--blue);
  cursor: default;
  border-style: dashed;
}

.cell.free-space:hover { transform: none; box-shadow: var(--shadow-sm); }

.cell-emoji {
  font-size: clamp(1.6rem, 3.5vw, 2.8rem);
  line-height: 1.1;
  pointer-events: none;
}

.cell-word {
  font-family: var(--font-body);
  font-size: clamp(0.75rem, 1.2vw, 1.05rem);
  font-weight: 700;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
  margin-top: 5px;
  pointer-events: none;
  word-break: break-word;
  hyphens: auto;
  letter-spacing: 0.2px;
}

/* =============================================
   TARJETA FLOTANTE DE CELEBRACIÓN
   ============================================= */

.celebration-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 50, 0.72);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlay-in 0.3s ease;
}

.celebration-overlay.hidden {
  display: none !important;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.celebration-card {
  position: relative;
  background: var(--surface);
  border-radius: 32px;
  padding: 52px 60px 48px;
  text-align: center;
  max-width: 520px;
  width: 90vw;
  overflow: hidden;
  box-shadow:
    0 24px 80px rgba(0,0,0,0.35),
    0 0 0 3px rgba(255,255,255,0.18);
  animation: card-pop 0.45s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes card-pop {
  from { transform: scale(0.6) translateY(40px); opacity: 0; }
  to   { transform: scale(1) translateY(0);      opacity: 1; }
}

/* Borde arcoíris animado para bingo */
.celebration-card.is-bingo::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 34px;
  background: conic-gradient(
    #FFD93D, #FF6B35, #FF6B9D, #C77DFF,
    #3A86FF, #6BCB77, #FFD93D
  );
  z-index: -1;
  animation: spin-border 3s linear infinite;
}

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

/* Borde sólido para línea */
.celebration-card.is-linea::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 34px;
  background: linear-gradient(135deg, var(--purple), #b39ddb, var(--purple));
  z-index: -1;
}

.celebration-card.is-bingo { background: #fffdf4; }
.celebration-card.is-linea { background: #faf8ff; }

/* Confetti canvas dentro de la tarjeta */
.celebration-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 32px;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall var(--dur, 1.2s) ease-in var(--delay, 0s) forwards;
  top: -20px;
  left: var(--x, 50%);
  background: var(--col, #FFD93D);
  transform: rotate(var(--rot0, 0deg));
}

@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(var(--rot0,0deg)); opacity: 1; }
  100% { transform: translateY(520px) rotate(var(--rot1,360deg)); opacity: 0; }
}

.celebration-close {
  position: absolute;
  top: 14px; right: 16px;
  background: rgba(0,0,0,0.08);
  border: none;
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  z-index: 2;
}

.celebration-close:hover {
  background: var(--red-light);
  color: var(--red);
}

.celebration-emoji {
  font-size: 82px;
  line-height: 1;
  margin-bottom: 16px;
  display: block;
  animation: emoji-wobble 0.7s cubic-bezier(0.34,1.56,0.64,1) both;
  position: relative;
  z-index: 1;
}

@keyframes emoji-wobble {
  from { transform: scale(0) rotate(-20deg); }
  to   { transform: scale(1) rotate(0deg); }
}

.celebration-title {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 900;
  margin-bottom: 10px;
  line-height: 1.1;
  position: relative;
  z-index: 1;
}

.is-bingo .celebration-title {
  background: linear-gradient(135deg, var(--amber-dark), var(--amber), #ff9900);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.is-linea .celebration-title {
  color: var(--purple);
}

.celebration-msg {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 28px;
  position: relative;
  z-index: 1;
}

.celebration-btn {
  display: inline-block;
  padding: 14px 42px;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  z-index: 1;
  letter-spacing: 0.3px;
}

.is-bingo .celebration-btn {
  background: linear-gradient(135deg, var(--amber), #ff9900);
  color: #fff;
  box-shadow: 0 5px 20px rgba(245,166,35,0.45);
}

.is-bingo .celebration-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(245,166,35,0.55);
}

.is-linea .celebration-btn {
  background: linear-gradient(135deg, var(--purple), #9b7be0);
  color: #fff;
  box-shadow: 0 5px 20px rgba(124,92,191,0.4);
}

.is-linea .celebration-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(124,92,191,0.5);
}

/* =============================================
   RESPONSIVE
   ============================================= */

@media (min-width: 1200px) {
  .cell-emoji { font-size: 2.5rem; }
  .cell-word  { font-size: 1rem; }
}

@media (max-width: 900px) {
  #game-screen { height: auto; overflow: auto; }
  .bingo-board { gap: 6px; }
}

@media (max-width: 800px) {
  .player-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 560px) {
  .setup-card h1 { font-size: 1.7rem; }
  .celebration-card { padding: 40px 28px 36px; }
  .celebration-title { font-size: 2rem; }
  .celebration-emoji { font-size: 60px; }
}
