/* =========================================================
   RatoLibre — Timbiriche: estilos propios del juego
   Depende de los tokens de ../../assets/css/base.css
   ========================================================= */

:root {
  --tb-tu: #2f6f4e;            /* verde: tus cuadros */
  --tb-tu-fondo: #d3eadc;
  --tb-pc: #93422f;            /* terracota: los de la computadora */
  --tb-pc-fondo: #f7d9cd;
  --tb-amarillo: #c97a00;      /* últimas rayas de la computadora */
  --tb-amarillo-halo: #fcd97a;
  --tb-guia: #e6dece;
  --tb-papel: #fffdf8;
}

/* ---------- Opciones de la barra ---------- */

/* En el celular: «Nuevo juego» a todo lo ancho y abajo las dos opciones */
.tb-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  gap: 10px 12px;
}

.tb-toolbar #nuevo {
  grid-column: 1 / -1;
}

.tb-opcion {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.tb-opcion select {
  width: 100%;
  min-height: 48px;
  padding: 0 34px 0 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%231f2a37' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M4 7l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

@media (hover: hover) {
  .tb-opcion select:hover {
    border-color: var(--accent);
  }
}

@media (min-width: 720px) {
  .tb-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
  }

  .tb-opcion select {
    min-width: 180px;
  }
}

/* ---------- Zona de juego ---------- */

.tb-area {
  /* En el celular ocupa todo el ancho para que el tablero sea más grande */
  margin-left: -16px;
  margin-right: -16px;
  max-width: none;
  padding: 12px 4px 14px;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}

@media (min-width: 480px) {
  .tb-area {
    margin-left: 0;
    margin-right: 0;
    padding: 16px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-radius: var(--radius);
  }
}

/* ---------- Iniciales en cuadrito (marcador, aviso y leyenda) ---------- */

.tb-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
}

.tb-chip.es-tu {
  background: var(--tb-tu-fondo);
  color: var(--tb-tu);
  box-shadow: inset 0 0 0 2px var(--tb-tu);
}

.tb-chip.es-pc {
  background: var(--tb-pc-fondo);
  color: var(--tb-pc);
  box-shadow: inset 0 0 0 2px var(--tb-pc);
}

/* ---------- Aviso de arriba (de quién es el turno y qué pasó) ---------- */

.tb-aviso {
  margin: 0 4px 10px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: center;
}

/* Siempre una línea de título y dos de texto, para que el tablero no salte */
.tb-aviso-titulo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 32px;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.25;
}

.tb-aviso-titulo .tb-chip {
  width: 28px;
  height: 28px;
  font-size: 0.8rem;
}

.tb-aviso-texto {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.7em;
  margin: 4px 0 0;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}

.tb-aviso-texto.es-nota {
  font-weight: 700;
  color: var(--accent-dark);
}

.tb-aviso.es-tu-turno,
.tb-aviso.es-ganaste {
  border-color: var(--accent-2);
  background: var(--accent-2-soft);
}

.tb-aviso.es-tu-turno .tb-aviso-titulo,
.tb-aviso.es-ganaste .tb-aviso-titulo {
  color: var(--accent-2);
}

.tb-aviso.es-turno-pc,
.tb-aviso.es-pausa,
.tb-aviso.es-empate {
  background: #f1ece3;
}

.tb-aviso.es-perdiste {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tb-aviso.es-perdiste .tb-aviso-titulo {
  color: var(--accent-dark);
}

@media (min-width: 600px) {
  .tb-aviso {
    margin: 0 0 12px;
  }

  .tb-aviso-titulo {
    font-size: 1.4rem;
  }
}

/* En pantallas muy angostas (320 px) la letra baja un poco para que el
   aviso siga en una línea de título y dos de texto */
@media (max-width: 359px) {
  .tb-aviso {
    padding: 8px 10px;
  }

  .tb-aviso-titulo {
    font-size: 1rem;
  }

  .tb-aviso-texto {
    font-size: 0.8rem;
  }
}

/* ---------- Marcador ---------- */

.tb-marcador {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  max-width: 460px;
  margin: 0 auto 12px;
  padding: 0 4px;
}

.tb-jugador {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 52px;
  padding: 6px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

/* En el celular el nombre va arriba y los cuadros abajo, para que
   «Computadora» quepa entera */
.tb-dato {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.tb-nombre {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
}

.tb-jugador strong {
  font-size: 1.4rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* De quién es el turno */
#marca-tu.es-turno {
  border-color: var(--tb-tu);
  background: var(--accent-2-soft);
}

#marca-pc.es-turno {
  border-color: var(--tb-pc);
  background: var(--accent-soft);
}

@media (min-width: 600px) {
  .tb-marcador {
    padding: 0;
  }

  .tb-dato {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .tb-nombre {
    font-size: 0.9rem;
  }

  .tb-jugador strong {
    font-size: 1.5rem;
  }
}

/* ---------- Tablero ---------- */

.tb-tablero {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 0 auto;
  border-radius: 14px;
  background: var(--tb-papel);
  box-shadow: inset 0 0 0 2px var(--border);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: opacity 0.2s ease;
}

.tb-tablero.is-pausado {
  opacity: 0.55;
}

.tb-dibujo {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.tb-zonas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Cada raya se toca en un rombo que va de punto a punto y tan ancho como la
   separación entre puntos: los rombos cubren todo el tablero sin encimarse */
.tb-zona {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  -webkit-clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tb-zona:focus {
  outline: none;
}

.tb-zona.es-trazada,
.tb-tablero:not(.es-mi-turno) .tb-zona {
  cursor: default;
}

/* Dibujo: el grueso de las rayas va en píxeles de pantalla */
.tb-guia {
  stroke: var(--tb-guia);
  stroke-width: 3px;
  stroke-linecap: round;
}

.tb-halo {
  stroke: transparent;
  stroke-width: 17px;
  stroke-linecap: round;
}

.tb-halo.es-ultima {
  stroke: var(--tb-amarillo-halo);
}

.tb-raya {
  stroke: transparent;
  stroke-width: 7px;
  stroke-linecap: round;
}

.tb-raya.es-trazada {
  stroke: var(--text);
}

.tb-raya.es-trazada.es-ultima {
  stroke: var(--tb-amarillo);
}

/* Vista previa de la raya (ratón o teclado) */
.tb-raya.es-fantasma {
  stroke: var(--accent-2);
  stroke-width: 7px;
  stroke-dasharray: 9 7;
  opacity: 0.75;
}

.tb-punto {
  fill: var(--text);
}

.tb-caja rect {
  fill: transparent;
}

.tb-caja text {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 52px;
  font-weight: 800;
}

.tb-caja.es-tu rect {
  fill: var(--tb-tu-fondo);
}

.tb-caja.es-tu text {
  fill: var(--tb-tu);
}

.tb-caja.es-pc rect {
  fill: var(--tb-pc-fondo);
}

.tb-caja.es-pc text {
  fill: var(--tb-pc);
}

/* La raya nueva se traza desde el centro y el cuadro cerrado aparece */
.tb-raya.es-nueva {
  transform-box: fill-box;
  transform-origin: center;
}

.tb-raya.es-nueva.de-lado {
  animation: tb-trazar-lado 0.3s ease-out;
}

.tb-raya.es-nueva.de-pie {
  animation: tb-trazar-pie 0.3s ease-out;
}

.tb-caja.es-nueva {
  transform-box: fill-box;
  transform-origin: center;
  animation: tb-pintar 0.4s ease-out;
}

@keyframes tb-trazar-lado {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

@keyframes tb-trazar-pie {
  from {
    transform: scaleY(0);
  }

  to {
    transform: scaleY(1);
  }
}

@keyframes tb-pintar {
  from {
    opacity: 0;
    transform: scale(0.5);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---------- Leyenda e información ---------- */

.tb-leyenda {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin: 14px 4px 0;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.3;
}

.tb-leyenda-dato {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tb-leyenda .tb-chip {
  width: 26px;
  height: 26px;
  font-size: 0.75rem;
}

.tb-muestra {
  display: inline-block;
  width: 28px;
  height: 7px;
  border-radius: 4px;
  background: var(--tb-amarillo);
  box-shadow: 0 0 0 5px var(--tb-amarillo-halo);
  margin: 0 5px;
}

.tb-info {
  margin: 8px 4px 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.tb-info:empty {
  display: none;
}

/* ---------- Paneles: fin de partida y confirmación ---------- */

.tb-panel {
  margin: 14px 4px 0;
  padding: 18px 14px;
  border: 2px solid var(--accent-2);
  border-radius: var(--radius);
  background: var(--accent-2-soft);
  text-align: center;
  animation: tb-aparecer 0.35s ease-out;
}

.tb-panel[hidden] {
  display: none;
}

.tb-panel:focus {
  outline: none;
}

.tb-panel .titulo {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--accent-2);
}

.tb-panel p {
  margin: 0 0 0.6rem;
}

.tb-panel p:empty {
  display: none;
}

.tb-panel .botones {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.tb-panel .botones .btn {
  flex: 1 1 220px;
  max-width: 340px;
}

.tb-confirmar {
  margin: 0 4px 14px;
}

.tb-panel.es-perdida,
.tb-confirmar {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tb-panel.es-perdida .titulo,
.tb-confirmar .titulo {
  color: var(--accent-dark);
}

.tb-panel.es-empate {
  border-color: var(--border);
  background: #f1ece3;
}

.tb-panel.es-empate .titulo {
  color: var(--text);
}

@keyframes tb-aparecer {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 600px) {
  .tb-panel {
    margin: 16px 0 0;
  }

  .tb-confirmar {
    margin: 0 0 16px;
  }

  .tb-panel .titulo {
    font-size: 1.6rem;
  }
}

/* ---------- Récords ---------- */

/* En el celular, dos por fila */
.tb-records {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px 18px;
  margin: 16px 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.tb-records .dato {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

@media (min-width: 600px) {
  .tb-records {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 28px;
    padding: 12px 18px;
  }

  .tb-records .dato {
    min-width: 6ch;
  }
}

.tb-records .etiqueta {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.tb-records strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Ayuda ---------- */

.tb-ayuda ol {
  padding-left: 1.4em;
}

.tb-ayuda li {
  margin-bottom: 0.5rem;
}

/* ---------- Movimiento reducido ---------- */

@media (prefers-reduced-motion: reduce) {
  .tb-raya.es-nueva.de-lado,
  .tb-raya.es-nueva.de-pie,
  .tb-caja.es-nueva,
  .tb-panel {
    animation: none;
  }

  .tb-tablero,
  .tb-jugador {
    transition: none;
  }
}
