/* connections.css — 16 personajes, 4 grupos ocultos.
   Misma paleta madera + oro que Nakama Draft, más un color por nivel de
   dificultad (amarillo → morado) que pinta los grupos, el mosaico de
   intentos, las estadísticas y la imagen para compartir. */

.container-connections,
.connections-results,
.connections-howto {
  --cx-gold: #ffb300;
  --cx-gold-soft: #ffd54f;
  --cx-wood: #3e2723;
  --cx-wood-deep: #2b1d18;
  --cx-ink: #2b1d18;
  --cx-spring: cubic-bezier(.34, 1.56, .64, 1);
  --cx-bump: cubic-bezier(.175, .885, .32, 1.275);
  /* Nivel: claro, intenso, tinta del texto. */
  /* Tonos de joya: vivos sobre fondo oscuro. */
  --cx-l1: #ffc83d; --cx-l1-deep: #c07a12; --cx-l1-ink: #1a1206;
  --cx-l2: #4fd88a; --cx-l2-deep: #17845a; --cx-l2-ink: #06150e;
  --cx-l3: #52b4ff; --cx-l3-deep: #1f63c2; --cx-l3-ink: #06101f;
  --cx-l4: #bb7dff; --cx-l4-deep: #6f35cf; --cx-l4-ink: #120824;
}

[data-level="1"] { --cx-light: var(--cx-l1); --cx-deep: var(--cx-l1-deep); --cx-level-ink: var(--cx-l1-ink); }
[data-level="2"] { --cx-light: var(--cx-l2); --cx-deep: var(--cx-l2-deep); --cx-level-ink: var(--cx-l2-ink); }
[data-level="3"] { --cx-light: var(--cx-l3); --cx-deep: var(--cx-l3-deep); --cx-level-ink: var(--cx-l3-ink); }
[data-level="4"] { --cx-light: var(--cx-l4); --cx-deep: var(--cx-l4-deep); --cx-level-ink: var(--cx-l4-ink); }

/* Iconos de línea compartidos con Nakama Draft (mismo sprite y trazo). */
.cx-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -0.12em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.connections-shell {
  width: min(580px, calc(100% - 20px));
  margin: 0 auto 28px;
  padding: 10px;
  border: 1px solid rgba(121, 85, 72, .62);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(45, 31, 20, .94), rgba(25, 17, 12, .97));
  box-shadow: 0 16px 42px rgba(0, 0, 0, .42);
  color: #fff8e1;
}

.container-connections {
  width: min(640px, calc(100% - 20px));
  margin: 0 auto 28px;
}
.container-connections .connections-game {
  margin: 0;
  color: var(--cx-wood);
  text-align: center;
  transition: box-shadow .4s ease;
}
.connections-instruction {
  margin: 0 0 20px;
  color: #5d4037;
  font-family: 'Pirata One', cursive;
  font-size: clamp(1.45rem, 4vw, 2rem);
  font-weight: 400;
  line-height: 1.08;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .65);
}

/* ============================================================
   ESTADO: vidas y selección
   ============================================================ */
.connections-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.connections-game .lives-bar,
.connections-selection-count {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  box-sizing: border-box;
  background: rgba(255, 248, 225, .8);
  border: 2px solid #8d6e63;
  border-radius: 50px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, .2);
}
.connections-game .lives-bar { gap: 8px; padding: 6px 16px; font-size: 1.55rem; }
.connections-game .life {
  position: relative;
  display: inline-flex;
  color: #d32f2f;
  transition: color .3s, opacity .3s, transform .3s var(--cx-bump);
}
.connections-game .life .cx-icon { fill: currentColor; stroke: #8e1c1c; stroke-width: 1.2; filter: drop-shadow(0 2px 1px rgba(0, 0, 0, .25)); }
.connections-game .life.lost { color: #bcaaa4; opacity: .45; transform: scale(.82); }
.connections-game .life.lost .cx-icon { stroke: #8d6e63; }
.connections-game .life.is-breaking { animation: connectionsHeartBreak .62s ease-out; }

.connections-selection-count {
  gap: 10px;
  padding: 6px 16px;
  color: var(--cx-wood);
  font-family: 'Pirata One', cursive;
  font-size: 1.05rem;
  letter-spacing: .4px;
  white-space: nowrap;
}
.connections-selection-dots { display: inline-flex; gap: 5px; }
.connections-selection-dots i {
  width: 10px;
  height: 10px;
  border: 2px solid #8d6e63;
  border-radius: 50%;
  background: transparent;
  transition: background .2s, border-color .2s, transform .25s var(--cx-bump);
}
.connections-selection-dots i.is-on { background: var(--cx-gold); border-color: #a65c00; transform: scale(1.15); }

/* ============================================================
   TABLERO
   ============================================================ */
.connections-board-wrap { position: relative; }
.connections-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  min-height: 0;
  padding: 8px;
  border: 2px solid #8d6e63;
  border-radius: 10px;
  background: var(--cx-wood);
  box-shadow: 0 0 20px rgba(0, 0, 0, .6), inset 0 0 12px rgba(0, 0, 0, .3);
  transition: border-color .3s, box-shadow .3s;
}
/* Última vida: el marco late en rojo para subir la tensión. */
.connections-game.is-last-chance .connections-board {
  border-color: #c62828;
  animation: connectionsDanger 1.6s ease-in-out infinite;
}
.connections-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  padding: 0;
  overflow: hidden;
  border: 1px solid #5d4037;
  border-radius: 5px;
  background: #2d201c;
  color: #fff;
  cursor: pointer;
  transition: background .3s ease, border-color .3s ease, box-shadow .3s ease, transform .25s var(--cx-spring);
}
.connections-card:hover { background: #444; border-color: var(--cx-gold); }
.connections-board.is-selection-full .connections-card.is-selection-locked {
  /* Sigue siendo clicable: pulsarla explica con el flash rojo que el límite
     es de selección, no que la carta esté deshabilitada. */
  cursor: pointer;
}
.connections-board.is-selection-full .connections-card.is-selection-locked:hover {
  background: #2d201c;
  border-color: #5d4037;
}
.connections-card:focus-visible { outline: 3px solid #4dd0e1; outline-offset: 2px; }
.connections-card.is-selected {
  z-index: 1;
  border: 3px solid #ffd700;
  background: #2a2a2a;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .35), 0 8px 18px rgba(0, 0, 0, .45), 0 0 16px rgba(255, 215, 0, .55);
  transform: translateY(-3px) scale(1.03);
}
.connections-card.is-selected::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(160deg, rgba(255, 224, 130, .28), transparent 45%);
  pointer-events: none;
}
.connections-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
}
.connections-card .character-name-overlay {
  position: absolute;
  z-index: 2;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 10px 2px 3px;
  background: linear-gradient(to top, rgba(0, 0, 0, .88) 0%, rgba(0, 0, 0, .4) 70%, transparent 100%);
  color: #e8ffe8;
  font-size: .65rem;
  font-weight: bold;
  text-align: center;
  pointer-events: none;
}
.connections-card.is-selected .character-name-overlay { color: #fff3c4; }
.connections-board.is-wrong { animation: connectionsShake .35s ease; }

/* Esqueleto de carga con el mismo brillo que Nakama Draft. */
.connections-skeleton {
  aspect-ratio: 1;
  border-radius: 5px;
  background: linear-gradient(100deg, #2d201c 30%, #4a342b 50%, #2d201c 70%);
  background-size: 300% 100%;
  animation: connectionsShimmer 1.3s linear infinite;
}

/* Carta que vuela del tablero al grupo (se crea en <body>). */
.connections-ghost {
  position: fixed;
  z-index: 1000;
  margin: 0;
  object-fit: cover;
  object-position: top center;
  border: 2px solid #ffd700;
  border-radius: 5px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, .45);
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform;
}

/* Aviso flotante: "¡Te falta uno!", "Ya lo has probado", "Última oportunidad". */
.connections-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  padding: 9px 20px;
  border: 2px solid #a65c00;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffe082, #ffb300);
  color: var(--cx-ink);
  font-family: 'Pirata One', cursive;
  font-size: clamp(1.2rem, 3.6vw, 1.6rem);
  letter-spacing: .5px;
  white-space: nowrap;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35), 0 10px 26px rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(.6);
}
.connections-toast[data-tone="danger"] { border-color: #7f1d1d; background: linear-gradient(135deg, #ff8a80, #e53935); color: #fff; }
.connections-toast[data-tone="info"] { border-color: #5d4037; background: linear-gradient(135deg, #fff8e1, #efdcb5); }
.connections-toast.is-visible { animation: connectionsToast 1.9s var(--cx-spring) both; }

/* ============================================================
   GRUPOS RESUELTOS
   ============================================================ */
.connections-solved { display: grid; gap: 9px; margin-bottom: 9px; }
/* Cada grupo lleva data-level: sus colores salen de [data-level] (arriba).
   Fondo oscuro teñido del nivel, con el icono de la categoría como marca de
   agua gigante, girada y cortada por el borde. */
.connections-group {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 126px;
  align-items: center;
  gap: 14px;
  min-height: 126px;
  padding: 10px 10px 10px 22px;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--cx-light) 70%, transparent);
  border-radius: 12px;
  background:
    radial-gradient(120% 140% at 0% 50%, color-mix(in srgb, var(--cx-deep) 55%, transparent) 0%, transparent 60%),
    linear-gradient(120deg, color-mix(in srgb, var(--cx-deep) 45%, #120c08) 0%, color-mix(in srgb, var(--cx-deep) 18%, #0d0906) 100%);
  color: #f3ece2;
  box-shadow:
    0 5px 0 rgba(0, 0, 0, .35),
    0 0 18px color-mix(in srgb, var(--cx-light) 28%, transparent),
    inset 0 1px 0 color-mix(in srgb, var(--cx-light) 35%, transparent);
}
.connections-group::before {
  /* Veta muy sutil, como en la madera del tablero. */
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: repeating-linear-gradient(100deg, rgba(255, 255, 255, .03) 0 2px, transparent 2px 14px);
  pointer-events: none;
}
.connections-group-mark {
  position: absolute;
  z-index: -1;
  left: calc((100% - 126px) / 2);
  top: 50%;
  width: 200px;
  height: 200px;
  color: var(--cx-light);
  opacity: .26;
  filter: blur(.6px) drop-shadow(0 0 10px color-mix(in srgb, var(--cx-light) 45%, transparent));
  transform: translate(-50%, -50%) rotate(-16deg);
  pointer-events: none;
}
.connections-group-mark .cx-icon { width: 100%; height: 100%; stroke-width: 1.3; }
.connections-group-copy { position: relative; min-width: 0; text-align: left; }
.connections-group h3 {
  margin: 0 0 5px;
  color: var(--cx-light);
  font-family: 'Pirata One', cursive;
  font-size: clamp(1.2rem, 2.8vw, 1.65rem);
  font-weight: 400;
  line-height: 1.05;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55), 0 0 14px color-mix(in srgb, var(--cx-light) 40%, transparent);
}
.connections-group p { margin: 0; color: #f3ece2; font-weight: 700; font-size: .88rem; opacity: .88; }
.connections-group-portraits {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: 126px;
  aspect-ratio: 1;
}
.connections-group-portraits img {
  width: 100%;
  height: 100%;
  min-width: 0;
  object-fit: cover;
  object-position: top center;
  border: 2px solid color-mix(in srgb, var(--cx-light) 65%, #000);
  border-radius: 6px;
  background: #2d201c;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45);
}

/* Revelado al perder: conserva su color de nivel pero apagado, con borde rojo
   discontinuo y la etiqueta "No acertada", para distinguirlo de los resueltos. */
.connections-group.is-revealed-loss {
  border: 2px dashed rgba(239, 83, 80, .8);
  background:
    radial-gradient(120% 140% at 0% 50%, color-mix(in srgb, var(--cx-deep) 28%, transparent) 0%, transparent 60%),
    linear-gradient(120deg, color-mix(in srgb, var(--cx-deep) 22%, #1a1411) 0%, color-mix(in srgb, var(--cx-deep) 8%, #110d0b) 100%);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .35), inset 0 0 22px rgba(0, 0, 0, .45);
}
.connections-group.is-revealed-loss::before {
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, .035) 0 8px, transparent 8px 16px);
}
.connections-group.is-revealed-loss .connections-group-mark {
  opacity: .13;
  filter: blur(.6px) saturate(.6);
}
.connections-group.is-revealed-loss h3 {
  color: color-mix(in srgb, var(--cx-light) 65%, #9e948a);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55);
}
.connections-group.is-revealed-loss p { opacity: .72; }
.connections-group.is-revealed-loss .connections-group-portraits img {
  border-color: color-mix(in srgb, var(--cx-light) 35%, #3e2723);
  filter: saturate(.45) brightness(.8);
}
.connections-group-missed {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 9px;
  border: 1px solid rgba(239, 83, 80, .8);
  border-radius: 999px;
  background: rgba(183, 28, 28, .35);
  color: #ffcdd2;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Entrada del grupo: el color se "pinta" de izquierda a derecha. Sin
   transform, para que los retratos de destino no se muevan mientras las
   cartas vuelan hacia ellos. */
.connections-group.is-appearing { opacity: 0; clip-path: inset(0 100% 0 0 round 12px); }
.connections-group.is-appearing.is-appearing-active {
  animation: connectionsGroupAppear .5s cubic-bezier(.22, .8, .24, 1) both;
}
.connections-group.is-revealed-loss.is-appearing.is-appearing-active { animation-duration: .42s; }
.connections-group.is-appearing .connections-group-copy { animation: connectionsCopyIn .45s ease .18s both; }

/* Mientras vuelan las cartas, los retratos reservan su hueco sin verse. */
.connections-group.is-landing .connections-group-portraits img { visibility: hidden; }
.connections-group.is-landing .connections-group-mark { opacity: 0; }
.connections-group.is-landed .connections-group-mark { animation: connectionsMarkIn .75s cubic-bezier(.2, .9, .25, 1.15) both; }
.connections-group.is-landed .connections-group-portraits img { animation: connectionsPortraitSettle .38s var(--cx-bump) both; }
.connections-group.is-landed .connections-group-portraits img:nth-child(2) { animation-delay: .04s; }
.connections-group.is-landed .connections-group-portraits img:nth-child(3) { animation-delay: .08s; }
.connections-group.is-landed .connections-group-portraits img:nth-child(4) { animation-delay: .12s; }
.connections-group.is-landed::after {
  /* Destello que cruza el banner cuando aparece el icono. */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, color-mix(in srgb, var(--cx-light) 35%, transparent) 50%, transparent 65%);
  transform: translateX(-100%);
  animation: connectionsSheen .7s ease .15s both;
  pointer-events: none;
}

/* ============================================================
   ACCIONES
   ============================================================ */
.connections-actions { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 16px; }
.connections-actions button, .connections-load-error button {
  min-width: 132px;
  padding: 10px 28px;
  border: 1px solid #6d4c41;
  border-radius: 12px;
  cursor: pointer;
  font-family: 'Pirata One', cursive;
  font-size: 1.15rem;
  letter-spacing: 1px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .45);
  box-shadow: 0 4px 0 #2b1d18, 0 6px 12px rgba(0, 0, 0, .3);
  transition: background .15s, border-color .15s, transform .1s, box-shadow .1s;
}
.connections-submit, .connections-load-error button { background: linear-gradient(135deg, #4e342e 0%, var(--cx-wood) 100%); color: #ffd700; }
.connections-submit:not(:disabled) { box-shadow: 0 4px 0 #1b1210, 0 0 0 2px rgba(255, 215, 0, .35), 0 6px 16px rgba(255, 179, 0, .3); }
.connections-clear { background: linear-gradient(135deg, #fff8e1 0%, #f0dfbe 100%); color: #4e342e; text-shadow: none; box-shadow: 0 4px 0 #a1887f, 0 6px 12px rgba(0, 0, 0, .2); }
.connections-actions button:hover:not(:disabled), .connections-load-error button:hover { border-color: #8d6e63; transform: translateY(-1px); }
.connections-actions button:active:not(:disabled), .connections-load-error button:active { transform: translateY(3px); box-shadow: 0 1px 0 #2b1d18, 0 2px 4px rgba(0, 0, 0, .3); }
.connections-actions button:disabled { opacity: .45; cursor: default; transform: none; }
.connections-announcer { min-height: 26px; margin-top: 12px; color: #5d4037; font-weight: 800; text-align: center; }
.connections-load-error { color: #8b1e1e; text-align: center; }

/* ============================================================
   RESULTADO: sello de rango, mosaico y estadísticas
   ============================================================ */
.connections-results { width: min(760px, calc(100% - 24px)); margin-inline: auto; }
/* Con el mosaico y su leyenda dentro, la tarjeta se apila siempre (texto arriba,
   intentos debajo): en fila, el texto quedaba demasiado estrecho en escritorio. */
.connections-results .game-result-content { flex-direction: column; }

/* Mosaico de intentos: ocupa todo el ancho de la tarjeta de victoria/derrota,
   bajo el título, sobre un panel oscuro para que colores e iconos se lean bien
   encima del verde o el rojo de la tarjeta. */
.connections-mosaic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
  padding: 16px 16px 14px;
  border: 1px solid rgba(255, 213, 79, .35);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(28, 20, 8, .88), rgba(37, 26, 10, .92));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 4px 12px rgba(0, 0, 0, .3);
}
.connections-mosaic:empty { display: none; }
.connections-mosaic-title {
  color: #fff8e1;
  font-family: 'Pirata One', cursive;
  font-size: .9rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .35);
}
.connections-mosaic-grid { display: flex; flex-direction: column; gap: 5px; }
.connections-mosaic-row { display: flex; align-items: center; gap: 5px; }
.connections-mosaic-mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 3px;
  border-radius: 50%;
  background: #8e2b2b;
  color: #fff;
  font-size: .72rem;
  font-weight: 900;
}
.connections-mosaic-row.is-correct .connections-mosaic-mark { background: #2e7d32; }
.connections-mosaic.is-animated .connections-mosaic-row { animation: connectionsChipIn .45s var(--cx-spring) backwards; }
.connections-mosaic-row span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  font-size: 1.45rem;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .25));
  border: 1px solid rgba(0, 0, 0, .3);
  border-radius: 7px;
  background: linear-gradient(135deg, var(--cx-light, #6d4c41), var(--cx-deep, #4e342e));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 2px 0 rgba(0, 0, 0, .3);
}
.connections-mosaic-row span .cx-icon { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .55)); }
/* Leyenda: los grupos del día con su color e icono. */
/* Leyenda en rejilla 2×2: un grupo por celda. */
.connections-mosaic-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  max-width: 460px;
  margin-top: 4px;
}
.connections-mosaic-chip {
  display: flex;
  min-width: 0;
  align-items: center;
  text-align: left;
  gap: 5px;
  padding: 3px 9px 3px 4px;
  border: 1px solid color-mix(in srgb, var(--cx-light) 70%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--cx-deep) 45%, rgba(0, 0, 0, .35));
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.2;
}
.connections-mosaic-chip i {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cx-light), var(--cx-deep));
  font-size: .8rem;
  font-style: normal;
}
.game-result-modal .connections-mosaic-caption {
  max-width: 560px;
  margin: 2px 0 0;
  color: rgba(255, 248, 225, .8);
  font-size: .74rem;
  line-height: 1.35;
}

.connections-stats { width: 100%; margin: 18px 0; padding: 14px 18px 16px; box-sizing: border-box; background: linear-gradient(135deg, #1c1408, #251a0a); border: 2px solid rgba(255, 179, 0, .45); border-radius: 10px; }
.connections-histogram-header { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; }
.connections-histogram-header::before, .connections-histogram-header::after { content: ''; flex: 1; height: 1px; background: rgba(255, 179, 0, .4); }
.connections-levels-header { margin-top: 16px; }
.connections-stats .connections-histogram-caption {
  margin: -4px 0 12px;
  color: rgba(255, 248, 225, .7);
  font-size: .78rem;
  line-height: 1.35;
  text-align: center;
}
.connections-stats .connections-histogram-caption strong { color: #ffd54f; font-weight: 800; }
/* Etiqueta "Tú" sobre la barra de la propia partida. */
.connections-histogram-you {
  position: absolute;
  top: 50%;
  right: 6px;
  z-index: 2;
  padding: 1px 7px;
  border-radius: 999px;
  background: #ffd54f;
  color: #2b1d18;
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
  transform: translateY(-50%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
.connections-histogram-bar.is-loss ~ .connections-histogram-you { background: #ef9a9a; }
.connections-histogram-title { color: #ffd54f; font-family: 'Pirata One', cursive; font-size: .82rem; letter-spacing: 2px; text-transform: uppercase; white-space: nowrap; }
.connections-histogram-rows { display: flex; flex-direction: column; gap: 5px; }
.connections-histogram-row { display: flex; align-items: center; gap: 8px; padding: 3px 5px; border-radius: 6px; }
.connections-histogram-row.is-mine { background: rgba(255, 213, 79, .09); }
.connections-histogram-label { display: grid; place-items: center; width: 38px; flex-shrink: 0; color: rgba(255, 255, 255, .5); font-family: 'Pirata One', cursive; font-size: 1rem; line-height: 1; text-align: center; }
.connections-histogram-row.is-mine .connections-histogram-label { color: #ffd54f; }
.connections-histogram-bar-wrap { position: relative; height: 24px; flex: 1; overflow: hidden; border-radius: 4px; background: rgba(0, 0, 0, .35); }
.connections-histogram-bar { width: 0; height: 100%; border-radius: 4px; background: rgba(255, 255, 255, .32); transition: width .65s cubic-bezier(.4, 0, .2, 1); }
.connections-histogram-row.is-mine .connections-histogram-bar { background: #ffd54f; box-shadow: 0 0 10px rgba(255, 213, 79, .5); }
.connections-histogram-bar.is-loss { background: rgba(255, 255, 255, .15); }
.connections-histogram-row.is-mine .connections-histogram-bar.is-loss { background: #ef5350; box-shadow: 0 0 10px rgba(239, 83, 80, .5); }
.connections-histogram-pct { width: 36px; flex-shrink: 0; color: rgba(255, 255, 255, .6); font-family: 'Roboto', sans-serif; font-size: .8rem; font-weight: bold; text-align: right; }
.connections-histogram-row.is-mine .connections-histogram-pct { color: #fff; }
.connections-histogram-pct.is-zero { color: rgba(255, 255, 255, .2); font-weight: normal; }
/* Filas por nivel: la barra lleva el color del grupo y su nombre encima. */
.connections-histogram-row.is-level .connections-histogram-label { color: var(--cx-light); font-size: 1.25rem; }
.connections-histogram-row.is-level .connections-histogram-bar { background: linear-gradient(90deg, var(--cx-deep), var(--cx-light)); }
.connections-histogram-row.is-level .connections-histogram-pct { color: var(--cx-light); }
.connections-level-name {
  position: absolute;
  inset: 0 8px;
  z-index: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  white-space: nowrap;
}

/* ============================================================
   TEASER Y CÓMO SE JUEGA
   ============================================================ */
.connections-teaser { text-align: center; max-width: 680px; }
.connections-teaser-mark { font-size: 4rem; filter: drop-shadow(0 8px 12px rgba(0,0,0,.4)); }
.connections-teaser-status { display: inline-block; padding: 5px 12px; border-radius: 999px; background: #ffb300; color: #26180e; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.connections-teaser h2 { margin: 15px 0 8px; font-family: "Pirata One", serif; color: #ffe082; font-size: clamp(2rem, 6vw, 3rem); }
.connections-teaser p { max-width: 560px; margin: 0 auto 22px; line-height: 1.6; }
.connections-teaser-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; max-width: 350px; margin: auto; }
.connections-teaser-grid span { aspect-ratio: 1; border-radius: 8px; background: linear-gradient(145deg, #183743, #0d222b); border: 1px solid #42616c; }

.connections-howto { text-align: center; }

/* ============================================================
   KEYFRAMES
   ============================================================ */
@keyframes connectionsShake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes connectionsGroupAppear {
  0%   { opacity: 0; clip-path: inset(0 100% 0 0 round 12px); filter: brightness(1.5); }
  15%  { opacity: 1; }
  70%  { clip-path: inset(0 0 0 0 round 12px); filter: brightness(1.15); }
  100% { opacity: 1; clip-path: inset(0 0 0 0 round 12px); filter: brightness(1); }
}
@keyframes connectionsCopyIn {
  0%   { opacity: 0; transform: translateX(-12px); }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes connectionsMarkIn {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(1.7) rotate(-48deg); }
  60%  { opacity: .32; transform: translate(-50%, -50%) scale(.94) rotate(-12deg); }
  100% { opacity: .26; transform: translate(-50%, -50%) scale(1) rotate(-16deg); }
}
@keyframes connectionsImprint {
  0%   { opacity: .75; transform: scale(.85); }
  100% { opacity: 0; transform: scale(1.35); }
}
@keyframes connectionsPortraitSettle {
  0%   { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes connectionsSheen {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@keyframes connectionsChipIn {
  0%   { opacity: 0; transform: translateX(-30px) scale(.9); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes connectionsHeartBreak {
  0%   { transform: scale(1); color: #d32f2f; }
  25%  { transform: scale(1.35) rotate(-10deg); color: #ff5252; }
  45%  { transform: scale(.9) rotate(8deg) translateY(2px); }
  65%  { transform: scale(1) rotate(-4deg); }
  100% { transform: scale(.82); }
}
@keyframes connectionsToast {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  14%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  24%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(.96); }
}
@keyframes connectionsDanger {
  0%, 100% { box-shadow: 0 0 20px rgba(0, 0, 0, .6), inset 0 0 12px rgba(0, 0, 0, .3); }
  50%      { box-shadow: 0 0 22px rgba(229, 57, 53, .75), inset 0 0 14px rgba(229, 57, 53, .35); }
}
@keyframes connectionsShimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   MÓVIL
   ============================================================ */
@media (max-width: 600px) {
  .container-connections { width: calc(100% - 10px); }
  .container-connections .connections-game { padding: 15px 10px; }
  .connections-shell { width: calc(100% - 10px); padding: 12px; border-radius: 13px; }
  .connections-instruction { margin-bottom: 14px; font-size: 1.38rem; }
  .connections-status { gap: 8px; margin-bottom: 12px; }
  .connections-game .lives-bar { gap: 5px; min-height: 37px; padding: 5px 12px; font-size: 1.25rem; }
  .connections-selection-count { gap: 7px; min-height: 37px; padding: 5px 12px; font-size: .9rem; }
  .connections-selection-dots i { width: 8px; height: 8px; }
  .connections-board { gap: 3px; min-height: 0; padding: 4px; }
  .connections-card.is-selected { border-width: 2px; }
  .connections-card .character-name-overlay { font-size: .55rem; padding: 8px 2px 2px; }
  .connections-group { grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; min-height: 96px; padding: 7px 7px 7px 14px; }
  .connections-group-mark { left: calc((100% - 96px) / 2); width: 150px; height: 150px; }
  .connections-group h3 { font-size: 1.05rem; }
  .connections-group p { font-size: .68rem; line-height: 1.2; }
  .connections-group-portraits { width: 96px; gap: 3px; }
  .connections-actions { gap: 7px; margin-top: 12px; }
  .connections-actions button, .connections-load-error button { min-width: 0; padding: 9px 18px; font-size: 1rem; }
  .connections-stats { padding: 12px 10px; }
  .connections-mosaic-row span { width: 34px; height: 34px; font-size: 1.2rem; }
}

@media (max-width: 380px) {
  .connections-board { gap: 2px; padding: 3px; }
  /* En Connections el nombre es parte esencial de la identificación: nunca se
     oculta en móvil, ni siquiera en los anchos más estrechos. */
  .connections-card .character-name-overlay { font-size: .48rem; line-height: 1.05; padding: 7px 1px 2px; }
  .connections-actions button { padding: 9px 13px; }
}

/* Movimiento reducido: sin vuelos, saltos ni latidos. La entrada de los grupos
   acertados se conserva a propósito (se pinta sin desplazamiento). */
html.tutorial-motion-reduce :is(.connections-card, .connections-game .life, .connections-histogram-bar,
  .connections-skeleton, .connections-mosaic-row, .connections-selection-dots i) {
  animation: none !important;
  transition: none !important;
}
html.tutorial-motion-reduce .connections-game.is-last-chance .connections-board { animation: none; box-shadow: 0 0 0 3px rgba(229, 57, 53, .6); }
html.tutorial-motion-reduce .connections-toast.is-visible { animation-duration: 2.2s; }
