/* ================================================================
   Palabra — fichas con relieve, revelado con flip 3D escalonado
   y teclado en pantalla con teclas físicas.
   Se carga DESPUÉS de style.css: pisa lo que haga falta de ahí.
   ================================================================ */

.wd-screen { gap: 14px; }

/* ---- marcador ---- */

.wd-screen .vs-bar {
  width: 100%;
  justify-content: center;
  gap: 10px;
  font-size: 1rem;
}

.wd-screen .vs-bar .player-you,
.wd-screen .vs-bar .player-opp {
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.01em;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wd-screen .vs-bar .player-you {
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.22), rgba(251, 191, 36, 0.10));
  box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.45);
}

.wd-screen .vs-bar .player-opp {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.22), rgba(56, 189, 248, 0.10));
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.45);
}

/* ---- tableros ---- */

.wd-boards {
  gap: 12px;
  align-items: flex-start;
}

.wd-grid {
  gap: 6px;
  /* la perspectiva va en cada transform (perspective()) para no crear un
     contexto 3D que aplane los box-shadow de las fichas vecinas */
}

.wd-grid.mini { gap: 3px; }

.wd-opp {
  gap: 6px;
  padding: 8px 8px 10px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.wd-opp-label {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.14);
  border-radius: 999px;
  padding: 3px 9px;
  max-width: 100px;
}

/* ---- ficha ---- */

.wd-cell {
  position: relative;
  border: none;
  border-radius: 10px;
  font-size: clamp(1.05rem, 5vw, 1.45rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #f0fdf4;
  /* relieve de ficha: luz arriba, apoyo abajo, sombra propia */
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -3px 0 rgba(0, 0, 0, 0.30),
    0 2px 5px rgba(0, 0, 0, 0.30);
  transition: box-shadow 0.18s ease, background 0.18s ease;
  will-change: transform;
}

/* el tablero del rival no gira (son celdas de 10px): la fila del rival se
   tiñe de izquierda a derecha con un delay escalonado por --i */
.wd-grid.mini .wd-cell {
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -1px 0 rgba(0, 0, 0, 0.28);
  transition: background 0.25s ease calc(var(--i, 0) * 0.09s);
}

/* letra recién tipeada: aro dorado + rebote corto */
.wd-cell.typing {
  background: linear-gradient(160deg, rgba(251, 191, 36, 0.26), rgba(251, 191, 36, 0.07));
  box-shadow:
    inset 0 0 0 2px rgba(251, 191, 36, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.30),
    0 0 14px rgba(251, 191, 36, 0.30),
    0 2px 5px rgba(0, 0, 0, 0.30);
  color: #fef3c7;
  animation: wd-pop 0.15s ease-out;
}

@keyframes wd-pop {
  0%   { transform: scale(0.88); }
  65%  { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* ---- estados revelados ----
   Cada estado repite su fondo/sombra dentro del keyframe del flip: así la
   ficha muestra la cara "en blanco" hasta que gira de canto (50%) y recién
   ahí aparece el color. Todo con transform/opacity, sin tocar layout. */

.wd-cell.filled { color: #ffffff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }

.wd-cell.g {
  background: linear-gradient(160deg, #22c55e, #15803d);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.38),
    inset 0 -3px 0 rgba(0, 0, 0, 0.28),
    0 3px 10px rgba(21, 128, 61, 0.45);
}

.wd-cell.y {
  background: linear-gradient(160deg, #eab308, #b45309);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.38),
    inset 0 -3px 0 rgba(0, 0, 0, 0.28),
    0 3px 10px rgba(180, 83, 9, 0.45);
}

.wd-cell.x {
  background: linear-gradient(160deg, rgba(15, 23, 42, 0.78), rgba(2, 6, 23, 0.88));
  color: #94a3b8;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -3px 0 rgba(0, 0, 0, 0.35);
}

/* marca de forma: el estado no depende solo del color */
.wd-cell.filled::after {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.52rem;
  font-weight: 900;
  line-height: 1;
  opacity: 0.8;
  pointer-events: none;
}

.wd-cell.g::after { content: '✓'; }
.wd-cell.y::after { content: '↔'; }
.wd-cell.x::after { content: '·'; opacity: 0.55; }
.wd-grid.mini .wd-cell::after { content: none; }

/* ---- flip 3D escalonado ---- */

.wd-cell.reveal {
  animation-duration: 0.5s;
  animation-timing-function: cubic-bezier(0.45, 0, 0.25, 1);
  animation-fill-mode: both;
  animation-delay: calc(var(--i, 0) * 0.15s);
}

.wd-cell.reveal::after {
  animation: wd-mark 0.5s both;
  animation-delay: calc(var(--i, 0) * 0.15s);
}

@keyframes wd-mark {
  0%, 49%   { opacity: 0; }
  50%, 100% { opacity: 0.8; }
}

.wd-cell.reveal.g { animation-name: wd-flip-g; }
.wd-cell.reveal.y { animation-name: wd-flip-y; }
.wd-cell.reveal.x { animation-name: wd-flip-x; }

@keyframes wd-flip-g {
  0% {
    transform: perspective(600px) rotateX(0deg);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(0, 0, 0, 0.30), 0 2px 5px rgba(0, 0, 0, 0.30);
  }
  49.9% {
    transform: perspective(600px) rotateX(-88deg) scale(1.04);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(0, 0, 0, 0.30), 0 2px 5px rgba(0, 0, 0, 0.30);
  }
  50% {
    transform: perspective(600px) rotateX(-92deg) scale(1.04);
    background: linear-gradient(160deg, #22c55e, #15803d);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), inset 0 -3px 0 rgba(0, 0, 0, 0.28), 0 3px 10px rgba(21, 128, 61, 0.45);
  }
  100% {
    transform: perspective(600px) rotateX(0deg);
    background: linear-gradient(160deg, #22c55e, #15803d);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), inset 0 -3px 0 rgba(0, 0, 0, 0.28), 0 3px 10px rgba(21, 128, 61, 0.45);
  }
}

@keyframes wd-flip-y {
  0% {
    transform: perspective(600px) rotateX(0deg);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(0, 0, 0, 0.30), 0 2px 5px rgba(0, 0, 0, 0.30);
  }
  49.9% {
    transform: perspective(600px) rotateX(-88deg) scale(1.04);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(0, 0, 0, 0.30), 0 2px 5px rgba(0, 0, 0, 0.30);
  }
  50% {
    transform: perspective(600px) rotateX(-92deg) scale(1.04);
    background: linear-gradient(160deg, #eab308, #b45309);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), inset 0 -3px 0 rgba(0, 0, 0, 0.28), 0 3px 10px rgba(180, 83, 9, 0.45);
  }
  100% {
    transform: perspective(600px) rotateX(0deg);
    background: linear-gradient(160deg, #eab308, #b45309);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), inset 0 -3px 0 rgba(0, 0, 0, 0.28), 0 3px 10px rgba(180, 83, 9, 0.45);
  }
}

@keyframes wd-flip-x {
  0% {
    transform: perspective(600px) rotateX(0deg);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(0, 0, 0, 0.30), 0 2px 5px rgba(0, 0, 0, 0.30);
  }
  49.9% {
    transform: perspective(600px) rotateX(-88deg) scale(1.04);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(0, 0, 0, 0.30), 0 2px 5px rgba(0, 0, 0, 0.30);
  }
  50% {
    transform: perspective(600px) rotateX(-92deg) scale(1.04);
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.78), rgba(2, 6, 23, 0.88));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 -3px 0 rgba(0, 0, 0, 0.35);
  }
  100% {
    transform: perspective(600px) rotateX(0deg);
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.78), rgba(2, 6, 23, 0.88));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 -3px 0 rgba(0, 0, 0, 0.35);
  }
}

/* palabra corta al mandar: la fila se sacude (va después de .typing para
   ganarle el animation-name a igual especificidad) */
.wd-cell.shake { animation: wd-shake 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }

@keyframes wd-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
  0%, 100% { transform: translateX(0); }
}

/* ---- teclado en pantalla ---- */

.wd-keyboard {
  gap: 7px;
  margin-top: 2px;
  padding: 10px 6px 8px;
  border-radius: 16px 16px 0 0;
  background: rgba(0, 0, 0, 0.26);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.wd-krow { gap: 4px; }

.wd-key {
  min-width: 0;
  padding: 13px 0 12px;
  border-radius: 9px;
  font-size: clamp(0.8rem, 3.6vw, 0.98rem);
  font-weight: 800;
  color: #f0fdf4;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0.13));
  /* la "altura" de la tecla es una sombra sólida abajo: al apretar, baja */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 3px 0 rgba(0, 0, 0, 0.38),
    0 4px 6px rgba(0, 0, 0, 0.26);
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.3s ease, color 0.3s ease;
  will-change: transform;
}

.wd-key:active {
  filter: none;
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 0 0 rgba(0, 0, 0, 0.38),
    0 1px 3px rgba(0, 0, 0, 0.3);
}

.wd-key.wide {
  max-width: 56px;
  font-size: 1.05rem;
  background: linear-gradient(180deg, rgba(134, 239, 172, 0.30), rgba(134, 239, 172, 0.14));
  color: #dcfce7;
}

/* teclas teñidas por lo ya jugado */
.wd-key.kg {
  background: linear-gradient(180deg, #22c55e, #15803d);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 3px 0 rgba(6, 78, 59, 0.9), 0 4px 6px rgba(0, 0, 0, 0.26);
}

.wd-key.ky {
  background: linear-gradient(180deg, #eab308, #b45309);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 3px 0 rgba(120, 53, 15, 0.9), 0 4px 6px rgba(0, 0, 0, 0.26);
}

.wd-key.kx {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.75), rgba(2, 6, 23, 0.85));
  color: #64748b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 2px 0 rgba(0, 0, 0, 0.45);
}

.wd-key.kx:active { transform: translateY(2px); }

/* estado + fin de ronda */

#wd-status {
  min-height: 20px;
  text-align: center;
  font-weight: 600;
}

/* pantallas muy angostas: que el teclado no se estire de más */
@media (max-width: 360px) {
  .wd-key { padding: 11px 0 10px; }
  .wd-keyboard { padding: 8px 2px 6px; }
  .wd-boards { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .wd-cell.reveal,
  .wd-cell.reveal::after,
  .wd-cell.typing,
  .wd-cell.shake { animation: none; }
}
