:root {
  --violeta: #6a1fc9;
  --violeta-osc: #3d0f86;
  --amarillo: #ffd21f;
  --naranja: #ff9d00;
  --verde: #39c04a;
  --blanco: #ffffff;
  --panel: rgba(20, 22, 90, .55);
  --sombra: 0 4px 0 rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: #0a3fd8 url("assets/ui/fondo.webp") center / cover no-repeat fixed;
  color: var(--blanco);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-weight: 700;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
img { -webkit-user-drag: none; }

#app {
  position: relative;
  max-width: 520px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

/* ---------- Barra superior ---------- */
.barra { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: 0 0 auto; }
.logo { height: 56px; width: auto; filter: drop-shadow(0 3px 2px rgba(0,0,0,.3)); }
.controles { display: flex; gap: 8px; align-items: center; }
.btn-redondo, .idioma {
  height: 40px; min-width: 40px; border-radius: 20px;
  background: var(--panel); display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--sombra);
}
.btn-redondo svg, .idioma svg { width: 22px; height: 22px; fill: currentColor; }
.btn-redondo .ico-off { display: none; }
.btn-redondo.mute .ico-on { display: none; }
.btn-redondo.mute .ico-off { display: block; }
.idioma { position: relative; padding: 0 10px; gap: 4px; cursor: pointer; }
.idioma select {
  appearance: none; -webkit-appearance: none; background: transparent; border: 0; color: inherit;
  font: inherit; font-size: 14px; max-width: 92px; cursor: pointer; outline: none;
}
.idioma select option { color: #222; }

/* ---------- Pantallas ---------- */
.pantalla { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; animation: entrar .3s ease; }
.pantalla.activa { display: flex; }
@keyframes entrar { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

h2 {
  margin: 10px 0 14px; text-align: center; font-size: 26px; letter-spacing: 1px;
  color: var(--amarillo);
  text-shadow: 0 3px 0 var(--violeta-osc), 0 0 2px var(--violeta-osc), 2px 0 0 var(--violeta-osc), -2px 0 0 var(--violeta-osc);
}

.grilla-categorias {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  overflow-y: auto; padding-bottom: 8px;
}
.cat {
  background: var(--panel); border-radius: 18px; padding: 10px 8px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: var(--sombra); transition: transform .12s;
}
.cat:last-child:nth-child(odd) { grid-column: 1 / -1; justify-self: center; width: calc(50% - 6px); }
.cat:active, .tab:active, .btn-icono:active, .store:active { transform: scale(.94); }
.cat .caras { position: relative; width: 100%; aspect-ratio: 1.35; }
.cat .caras img {
  position: absolute; width: 58%; top: 6%; border-radius: 12px;
  box-shadow: 0 3px 6px rgba(0,0,0,.3);
}
.cat .caras img:nth-child(1) { left: 4%; transform: rotate(-9deg); }
.cat .caras img:nth-child(2) { right: 4%; transform: rotate(9deg); }
.cat span { font-size: 15px; text-align: center; line-height: 1.15; }

.titulo-con-volver { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; }
.mini-cat { width: 44px; border-radius: 10px; justify-self: end; }
.btn-icono img { width: 44px; height: auto; display: block; filter: drop-shadow(0 3px 2px rgba(0,0,0,.3)); }
.btn-icono.grande img { width: 72px; }

.grilla-tableros { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tab {
  background: var(--panel); border-radius: 18px; padding: 14px 10px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: var(--sombra); transition: transform .12s;
}
.tab .mini {
  display: grid; gap: 3px; height: 112px; aspect-ratio: var(--ar);
}
.tab .mini i { background: linear-gradient(#9b5cff, #5b1fd0); border-radius: 3px; border: 1px solid rgba(255,255,255,.6); }
.tab .tam { font-size: 18px; }
.tab .mejor { display: flex; gap: 2px; font-size: 18px; color: rgba(255,255,255,.25); }
.tab .mejor .on { color: var(--amarillo); }

/* ---------- Juego ---------- */
.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: var(--panel); border-radius: 16px; padding: 6px 10px; box-shadow: var(--sombra);
  flex: 0 0 auto; margin-top: 6px;
}
.hud .btn-icono img { width: 38px; }
.dato { display: flex; align-items: center; gap: 4px; font-size: 20px; min-width: 64px; }
.dato img { width: 32px; height: 32px; object-fit: contain; }
.estrella-mini { color: var(--amarillo); font-size: 26px; line-height: 1; }
.dato.puntos { justify-content: flex-end; }

#zonaTablero { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 10px 0; }
#tablero { display: grid; gap: var(--gap, 6px); }

.carta { position: relative; width: var(--lado); height: var(--lado); perspective: 600px; }
.carta .gira {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .32s ease; transform: rotateY(0deg);
}
.carta.vuelta .gira { transform: rotateY(180deg); }
.carta .cara {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 14%; overflow: hidden;
}
.carta .cara img { width: 100%; height: 100%; display: block; }
.carta .frente { transform: rotateY(180deg); }
.carta.par .frente { animation: par .45s ease; box-shadow: 0 0 0 3px var(--amarillo), 0 0 14px var(--amarillo); }
.carta.error .frente { animation: sacude .35s ease; }
.carta.reparte { animation: reparte .35s ease backwards; }
@keyframes par { 50% { transform: rotateY(180deg) scale(1.12); } }
@keyframes sacude { 25% { translate: -4px 0; } 75% { translate: 4px 0; } }
@keyframes reparte { from { opacity: 0; transform: translateY(-40px) scale(.6); } }

#popups { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.popup {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  font-size: 40px; color: var(--amarillo); white-space: nowrap;
  text-shadow: 0 4px 0 var(--violeta-osc), 3px 0 0 var(--violeta-osc), -3px 0 0 var(--violeta-osc), 0 -3px 0 var(--violeta-osc);
  animation: popup 1s ease forwards;
}
.popup small { display: block; text-align: center; font-size: 22px; color: var(--blanco); }
@keyframes popup {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.4); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(.9); }
}

/* ---------- Fin ---------- */
.overlay {
  position: absolute; inset: 0; background: rgba(8, 10, 50, .6);
  display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 5;
}
.overlay[hidden] { display: none; }
.panel {
  width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto;
  background: linear-gradient(#7d34e6, #4a14a8); border: 4px solid #b58cff; border-radius: 26px;
  padding: 16px 16px 18px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: aparece .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes aparece { from { transform: scale(.6); opacity: 0; } }
.panel h2 { margin: 4px 0 6px; }
.estrellas { display: flex; justify-content: center; gap: 6px; font-size: 58px; line-height: 1; }
.estrellas span { color: rgba(0,0,0,.28); }
.estrellas span:nth-child(2) { transform: translateY(-12px); font-size: 70px; }
.estrellas span.on { color: var(--amarillo); text-shadow: 0 0 12px rgba(255,210,31,.7), 0 3px 0 var(--naranja); animation: estrella .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes estrella { from { transform: scale(0) rotate(-90deg); } }
.estrellas span:nth-child(2).on { animation-name: estrella2; }
@keyframes estrella2 { from { transform: translateY(-12px) scale(0) rotate(-90deg); } }
.frase { margin: 6px 0; font-size: 20px; min-height: 24px; }
.resumen { display: flex; justify-content: center; gap: 24px; }
.puntaje { font-size: 44px; color: var(--amarillo); text-shadow: 0 3px 0 var(--violeta-osc); }
.record { min-height: 22px; font-size: 16px; opacity: .9; }
.record.nuevo { color: var(--amarillo); animation: latido 1s ease infinite; }
@keyframes latido { 50% { transform: scale(1.08); } }
.acciones { display: flex; justify-content: center; gap: 24px; margin: 8px 0 12px; }
.descarga { border-top: 2px solid rgba(255,255,255,.2); padding-top: 10px; }
.descarga p { margin: 0 0 8px; font-size: 15px; }
.stores { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.store {
  display: inline-flex; align-items: center; gap: 6px; background: #000; color: #fff; text-decoration: none;
  border: 1px solid #a6a6a6; border-radius: 9px; padding: 5px 12px 5px 9px; text-align: left; font-size: 16px; line-height: 1.05;
  transition: transform .12s;
}
.store svg { width: 24px; height: 24px; }
.store small { display: block; font-size: 9px; font-weight: 400; text-transform: uppercase; }
.store[hidden] { display: none; }

/* RTL */
[dir="rtl"] .store { text-align: right; }

@media (max-height: 640px) {
  .logo { height: 42px; }
  h2 { font-size: 22px; margin: 6px 0 10px; }
  .tab .mini { height: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
