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

:root {
  --fondo: #fdf6ec;
  --tinta: #3b2b20;
  --acento: #7c5cbf;
  --acento-suave: #ede7f6;
  --verde: #2e7d32;
  --casilla-clara: #f5e9d3;
  --casilla-oscura: #b48b60;
  --seleccion: #ffd95c;
  --radius: 18px;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  display: flex;
  justify-content: center;
}

#app { width: 100%; max-width: 480px; padding: 16px; }
.view { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 12px; }
.oculto { display: none !important; }

.titulo { font-size: 1.9rem; margin-top: 12px; text-align: center; }
.subtitulo { color: #7a6a5c; text-align: center; }
h2 { text-align: center; }
.error { color: #c62828; font-weight: 600; }

/* Tarjetas de usuarios */
.tarjetas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.tarjeta {
  background: #fff; border: 3px solid #eadfce; border-radius: var(--radius);
  padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; transition: transform .1s, border-color .1s; font-size: 1.05rem; font-weight: 700;
  position: relative;
}
.tarjeta:active { transform: scale(.96); }
.tarjeta svg { width: 72px; height: 72px; }
.tarjeta .estado { font-size: .8rem; font-weight: 600; color: #9e9e9e; }
.tarjeta.online .estado { color: var(--verde); }
.tarjeta .punto { position: absolute; top: 10px; right: 10px; width: 12px; height: 12px; border-radius: 50%; background: #cfcfcf; }
.tarjeta.online .punto { background: #4caf50; box-shadow: 0 0 6px #4caf50; }
.tarjeta button {
  border: 0; background: var(--acento); color: #fff; font-weight: 700; font-size: .95rem;
  padding: 8px 14px; border-radius: 12px; cursor: pointer;
}
.tarjeta button:disabled { background: #d7cfc4; }

/* PIN */
.avatar-grande svg, .avatar-grande { width: 110px; height: 110px; }
.pin-dots { display: flex; gap: 14px; margin: 6px 0; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--acento); }
.pin-dots span.lleno { background: var(--acento); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.pin-pad button {
  height: 64px; font-size: 1.5rem; font-weight: 700; border-radius: 16px;
  border: 3px solid #eadfce; background: #fff; color: var(--tinta); cursor: pointer;
}
.pin-pad button:active { background: var(--acento-suave); }
.volver { align-self: flex-start; border: 0; background: none; font-size: 1rem; color: var(--acento); font-weight: 700; cursor: pointer; }

/* Avatares */
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.avatar-op { background: #fff; border: 3px solid #eadfce; border-radius: var(--radius); padding: 8px; cursor: pointer; text-align: center; }
.avatar-op svg { width: 100%; height: auto; }
.avatar-op .nombre { font-size: .75rem; font-weight: 700; }
.avatar-op.elegido { border-color: var(--acento); background: var(--acento-suave); }

.boton-principal {
  background: var(--acento); color: #fff; border: 0; border-radius: 16px;
  font-size: 1.15rem; font-weight: 800; padding: 14px 34px; cursor: pointer; width: 100%;
}
.boton-principal:disabled { background: #d7cfc4; }
.boton-secundario {
  background: #fff; color: var(--acento); border: 3px solid var(--acento); border-radius: 16px;
  font-size: 1rem; font-weight: 800; padding: 12px 24px; cursor: pointer; width: 100%;
}
.boton-chico {
  border: 3px solid #eadfce; background: #fff; border-radius: 14px; font-size: 1.15rem;
  width: 46px; height: 46px; cursor: pointer;
}
.boton-chico.grande { width: 58px; height: 58px; font-size: 1.4rem; }
.boton-etiqueta {
  border: 3px solid #eadfce; background: #fff; border-radius: 14px; font-size: .9rem;
  font-weight: 700; color: var(--tinta); height: 46px; padding: 0 12px; cursor: pointer;
}
.boton-chico.activo { border-color: var(--verde); background: #e8f5e9; }

/* Lobby */
.lobby-header { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.lobby-header-botones { display: flex; gap: 8px; }
.yo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; }
.yo svg { width: 52px; height: 52px; }

/* Tablero */
#tablero-wrap { width: 100%; }
#tablero {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  width: 100%; aspect-ratio: 1/1;
  border-radius: 12px; overflow: hidden; border: 4px solid #8a6642;
  touch-action: manipulation;
}
.casilla {
  position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer;
  min-width: 0; min-height: 0; /* que el contenido nunca estire la celda */
}
.casilla.clara { background: var(--casilla-clara); }
.casilla.oscura { background: var(--casilla-oscura); }
.casilla img { width: 88%; height: 88%; object-fit: contain; pointer-events: none; }
.casilla.seleccionada { background: var(--seleccion); }
.casilla.ultima { box-shadow: inset 0 0 0 100px rgba(255, 217, 92, .45); }
.casilla.jaque { box-shadow: inset 0 0 0 100px rgba(229, 57, 53, .5); }
.casilla .destino {
  width: 30%; height: 30%; border-radius: 50%; background: rgba(60, 120, 60, .5); position: absolute;
}
.casilla .captura {
  position: absolute; inset: 4%; border: 4px dashed rgba(60, 120, 60, .65); border-radius: 14%;
}
.casilla .coord { position: absolute; bottom: 2px; right: 3px; font-size: .55rem; font-weight: 700; opacity: .55; }

.jugador { width: 100%; display: flex; align-items: center; gap: 10px; font-weight: 800; padding: 4px 2px; min-height: 46px; }
.jugador-datos { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.jugador-datos svg { width: 42px; height: 42px; flex-shrink: 0; }
.jugador-datos .turno-tag { margin-left: auto; font-size: .85rem; background: #e8f5e9; color: var(--verde); border-radius: 10px; padding: 4px 10px; white-space: nowrap; }
.jugador-datos.espera .turno-tag { background: #f5f5f5; color: #9e9e9e; }
.jugador-datos .voz-tag { font-size: .8rem; color: var(--verde); }
.video-cara {
  width: 82px; height: 82px; border-radius: 16px; object-fit: cover; flex-shrink: 0;
  border: 3px solid var(--verde); background: #222;
}
.video-cara.espejo { transform: scaleX(-1); }

.game-status { min-height: 26px; font-weight: 800; text-align: center; font-size: 1.05rem; }
.game-botones { display: flex; gap: 14px; justify-content: center; }

/* Modal */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(40, 30, 20, .55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-caja {
  background: #fff; border-radius: 22px; padding: 24px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center;
}
.modal-caja h3 { font-size: 1.25rem; }
.modal-caja img.qr { width: 240px; height: 240px; border-radius: 12px; }
.modal-caja .fila-botones { display: flex; gap: 10px; width: 100%; }
.modal-caja .fila-botones button { flex: 1; }
.modal-caja svg { width: 84px; height: 84px; }
.modal-caja .link-caja {
  font-size: .78rem; background: #f6f1e8; padding: 8px; border-radius: 10px; word-break: break-all; width: 100%;
}
.piezas-promo { display: flex; gap: 10px; }
.piezas-promo button { width: 64px; height: 64px; border-radius: 14px; border: 3px solid #eadfce; background: #fff; cursor: pointer; }
.piezas-promo img { width: 80%; height: 80%; }

/* Estadísticas */
.stats-lista { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.stats-fila {
  background: #fff; border: 3px solid #eadfce; border-radius: var(--radius);
  padding: 10px 12px; display: flex; align-items: center; gap: 8px;
}
.stats-fila svg { width: 44px; height: 44px; flex-shrink: 0; }
.stats-fila .stats-nombre { font-weight: 800; font-size: .98rem; min-width: 0; overflow-wrap: anywhere; }
.stats-fila .stats-numeros { display: flex; gap: 5px; margin-left: auto; text-align: center; flex-shrink: 0; }
.stats-num { min-width: 40px; }
.stats-num b { display: block; font-size: 1.15rem; }
.stats-num span { font-size: .62rem; font-weight: 700; color: #9b8b7a; }
.stats-num.ganadas b { color: var(--verde); }
.stats-num.perdidas b { color: #c62828; }
.stats-fila.primera { border-color: #f4c430; background: #fffaea; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--tinta); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-weight: 700; z-index: 60; max-width: 90%; text-align: center;
}

@media (min-width: 700px) {
  #app { max-width: 560px; }
}
