/* ============================================================
   Impulso Ajedrez — Identidad visual (guiño a Impulso Escolar)
   Paleta: azul #4F6DFF · tinta #142179 · acento #E91E63
   Énfasis: cyan #A0E8F2 · magenta #F4A6D7 · amarillo #FFF599
   Tipografía: Montserrat
   ============================================================ */

:root {
  /* modo claro: azul de marca (#142179) para texto/botones */
  --azul: #142179;
  --azul-suave: #7D90E8;
  --tinta: #142179;
  --gris: #555555;
  --acento: #E91E63;
  --cyan: #A0E8F2;
  --magenta: #F4A6D7;
  --amarillo: #FFF599;
  --fondo: #F9FCFE;
  --blanco: #FFFFFF;
  --casilla-clara: #EAF0FB;
  --casilla-oscura: #8FA2EE;
  --verde: #7DDBA3;
  --amarillo-jugada: #FFE173;
  --rojo-claro: #F1948A;
  --rojo-amenaza: rgba(241, 148, 138, 0.4);
  --radio: 10px;
  --sombra: 0 2px 6px rgba(20, 33, 121, 0.08);
}

body.dark {
  /* modo oscuro: azul de marca vivo (#4F6DFF) + profundo */
  --azul: #4F6DFF;
  --fondo: #0D1547;
  --blanco: #18205E;
  --tinta: #EAF0FB;
  --gris: #B9C2E8;
  --casilla-clara: #C7D2F5;
  --casilla-oscura: #5B6FD6;
  --sombra: 0 2px 8px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Montserrat', sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  line-height: 1.55;
  min-height: 100vh;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: var(--blanco);
  box-shadow: var(--sombra);
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  font-weight: 800;
  font-size: 24px;
  color: var(--azul);
  cursor: pointer;
  user-select: none;
}
.logo-piece { color: var(--acento); }
.logo-all { color: var(--tinta); }

.mainnav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
/* botón hamburguesa (solo visible en pantalla estrecha) */
.nav-burger {
  display: none;
  font-size: 22px; line-height: 1;
  background: transparent; border: 2px solid var(--azul); color: var(--azul);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-weight: 800;
}

.navbtn {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border: none;
  background: transparent;
  color: var(--gris);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.navbtn:hover { background: var(--casilla-clara); color: var(--tinta); }
.navbtn.active { background: var(--azul); color: #fff; }
/* botón "En directo": punto rojo parpadeante de retransmisión */
.navbtn[data-view="live"]:not(.active) { color: var(--acento); }
.navbtn[data-view="live"]::before {
  content: "● "; color: var(--acento);
  animation: livePulse 1.6s ease-in-out infinite;
}
.navbtn[data-view="live"].active::before { color: #fff; }

.langbtn {
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  border: none;
  color: #fff;
  background: var(--azul);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  line-height: 1.1;
}
.langbtn:hover { background: #3d59e8; }
#langToggle { padding: 7px 10px; }
.flag-ico { display: block; width: 24px; height: 16px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.65); }
/* botón temporal "Socio" (previsualizar premium): gris=desactivado, azul de marca=activado */
.member-toggle { font-family: inherit; font-weight: 800; font-size: 13px; border: none; border-radius: 8px; padding: 6px 12px; cursor: pointer; background: #cbd0db; color: #6b7280; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.member-toggle:hover { filter: brightness(.97); }
.member-toggle.on { background: #142179; color: #fff; box-shadow: 0 2px 8px rgba(20,33,121,.3); }

/* ---------- Racha (CTA en color acento + explicación) ---------- */
.streak-wrap { position: relative; display: inline-block; }
.streak-pill {
  font-family: inherit; font-weight: 800; font-size: 13px;
  background: var(--acento); color: #fff; border: none; cursor: pointer;
  border-radius: 999px; padding: 7px 13px; display: inline-flex; gap: 6px; align-items: center;
  box-shadow: 0 2px 8px rgba(233,30,99,.35);
}
.streak-pill:hover { filter: brightness(1.06); }
.streak-info {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 70;
  width: min(290px, 82vw); background: var(--blanco); color: var(--tinta);
  border: 1.5px solid var(--acento); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 10px 28px rgba(20,33,121,.2); font-size: 13px; line-height: 1.5; font-weight: 500;
}
/* indicador de intentos del reto + botón reiniciar nivel */
.reto-attempts { font-weight: 700; color: var(--gris); font-size: 13px; min-height: 16px; margin-bottom: 6px; }
.btn-reset { border-color: var(--acento) !important; color: var(--acento) !important; }

/* propuesta del Reto del día al acabar (toast inferior, no intrusivo) */
.reto-suggest {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 300;
  background: var(--blanco); border: 1.5px solid var(--acento); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(20,33,121,.25); padding: 11px 15px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; max-width: 92vw;
  font-weight: 600; color: var(--tinta); animation: retoToastIn .3s ease;
}
.reto-suggest .btn { margin-top: 0; }
@keyframes retoToastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Onboarding (tour de bienvenida) ---------- */
.onb-backdrop {
  position: fixed; inset: 0; z-index: 500; padding: 20px;
  background: rgba(13,21,71,.55); display: flex; align-items: center; justify-content: center;
}
.onb-card {
  background: var(--blanco); color: var(--tinta); border-radius: 18px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4); padding: 26px 24px; max-width: 380px; width: 100%;
  animation: onbIn .3s ease;
}
.onb-av { width: 96px; height: 96px; object-fit: contain; margin: 0 auto 6px; display: block; }
.onb-title { font-size: 20px; font-weight: 800; color: var(--azul); margin: 0 0 6px; }
.onb-text { font-size: 15px; line-height: 1.5; margin: 0 0 14px; color: var(--tinta); }
.onb-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; }
.onb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--azul-suave); opacity: .5; }
.onb-dot.on { opacity: 1; background: var(--acento); transform: scale(1.15); }
.onb-actions { display: flex; gap: 12px; justify-content: center; align-items: center; }
.onb-next { font-family: inherit; font-weight: 800; font-size: 16px; padding: 12px 26px; border: none; border-radius: 12px; background: var(--azul); color: #fff; cursor: pointer; }
.onb-next:hover { background: #3d59e8; }
.onb-skip { font-family: inherit; font-weight: 600; font-size: 13px; background: transparent; border: none; color: var(--gris); cursor: pointer; text-decoration: underline; }
@keyframes onbIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Socios: avisos (barra) y bloqueos (capa) ---------- */
#view-learn, #view-puzzles { position: relative; }
.member-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--cyan); color: #142179; border-radius: 10px;
  padding: 8px 14px; margin-bottom: 14px; font-weight: 600; font-size: 13.5px;
}
.member-bar .member-cta {
  margin-left: auto; background: var(--acento); color: #fff; text-decoration: none;
  font-weight: 800; font-size: 13px; padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.member-bar .member-cta:hover { background: #c81a55; }
/* grupo de acciones de la barra: "ya eres socio" + "hazte socio" */
.member-bar .member-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.member-bar .member-actions .member-cta { margin-left: 0; }
.member-bar .member-login { color: #142179; font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap; }
.member-bar .member-login:hover { opacity: .75; }
/* botón "Acceso" del header */
.login-btn { font-family: inherit; font-weight: 800; font-size: 13px; border: 1px solid #142179; border-radius: 999px; padding: 6px 14px; cursor: pointer; background: #fff; color: #142179; white-space: nowrap; transition: background .15s, color .15s; }
.login-btn:hover { background: #142179; color: #fff; }
.login-btn.is-in { background: #142179; color: #fff; }
.login-btn.is-premium { background: #142179; color: #FFD64A; }
/* nota de acceso (cuando aún no hay backend) en Ajustes */
.account-soon h3 { margin-top: 0; }
/* botones del popup de bloqueo (Aprender): Acceso azul + Hazte socio CTA */
.view-lock-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.btn-access { background: #142179; color: #fff; border-color: #142179; }
.btn-access:hover { background: #0e1858; color: #fff; }
.btn-cta { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
/* claro: relleno y BORDE en color CTA (rosa). Oscuro: se mantiene el botón de marca azul (tema). */
body:not(.dark) .btn.btn-cta { background: var(--acento); color: #fff; border-color: var(--acento); }
.btn-cta:hover { filter: brightness(.96); }
/* cohete de Impulso Escolar en los CTA de "Hazte socio" (blanco sobre fondo de color) */
.cta-rocket { height: 1.05em; width: auto; vertical-align: -0.15em; margin-right: 7px; flex: 0 0 auto; }
/* CTA "Hazte socio" del Reto: botón sin subrayado (el fondo lo pone el JS según la asignatura) */
.reto-cta { display: inline-flex; align-items: center; justify-content: center; color: #fff; border: none; border-radius: 12px; padding: 11px 18px; font-weight: 800; text-decoration: none; margin-top: 4px; }
.reto-cta:hover { filter: brightness(.95); color: #fff; }
/* nunca subrayar los botones */
.btn, a.btn { text-decoration: none; }
/* ----- modal de Acceso (código de 6 cifras) ----- */
.login-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-modal[hidden] { display: none; }
.login-backdrop { position: absolute; inset: 0; background: rgba(10,14,40,.55); }
.login-card { position: relative; background: var(--card, #fff); color: var(--texto, #1a1a1a); width: 100%; max-width: 520px; border-radius: 16px; padding: 26px 24px 20px; box-shadow: 0 18px 50px rgba(0,0,0,.3); display: flex; align-items: stretch; gap: 16px; }
.login-avatar { width: 118px; flex: 0 0 auto; align-self: stretch; object-fit: contain; object-position: bottom center; }
.login-body { flex: 1 1 auto; min-width: 0; }
@media (max-width: 520px) { .login-card { max-width: 420px; } .login-avatar { display: none; } }
.login-x { position: absolute; top: 8px; right: 12px; border: none; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: #94a0b8; }
.login-x:hover { color: #142179; }
.login-h { margin: 0 0 10px; color: #142179; font-size: 21px; }
.login-lead { font-size: 14px; line-height: 1.5; margin: 0 0 14px; }
.login-modal input[type=email], .login-code { width: 100%; box-sizing: border-box; padding: 12px 14px; border: 1.5px solid #c9cfdd; border-radius: 10px; font-size: 16px; font-family: inherit; }
.login-code { text-align: center; letter-spacing: 10px; font-weight: 800; font-size: 24px; }
.login-wide { width: 100%; margin-top: 12px; padding: 12px; font-size: 15px; }
.login-remember { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: #4a5568; margin: 12px 2px 2px; line-height: 1.4; cursor: pointer; }
.login-remember input { margin-top: 2px; flex: 0 0 auto; }
.login-sublinks { display: flex; justify-content: space-between; margin-top: 10px; }
.login-link { background: none; border: none; color: #142179; font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; font-family: inherit; }
.login-msg { font-size: 13px; margin: 12px 0 0; padding: 8px 10px; border-radius: 8px; }
.login-msg.err { background: #fdecef; color: #c81a55; }
.login-msg.info { background: #eef0fb; color: #142179; }
.login-note { font-size: 12px; color: #6b7280; margin: -4px 0 12px; line-height: 1.4; }
.login-foot { font-size: 12.5px; color: #6b7280; margin: 16px 0 0; text-align: center; }
.login-foot a { color: #142179; font-weight: 700; }
.login-join-wrap { text-align: center; margin-top: 8px; }
.login-join { display: inline-block; padding: 10px 20px; font-size: 14px; }
body.login-open { overflow: hidden; }
.gated { filter: grayscale(.9) opacity(.6); pointer-events: none; }
.view-lock {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-start; justify-content: center;
  padding: 24px; background: rgba(247,249,253,.7);
}
.view-lock[hidden] { display: none; }
.view-lock-box {
  background: var(--blanco); border: 1.5px solid var(--azul-suave); border-radius: 16px;
  padding: 24px 26px; max-width: 440px; text-align: center; box-shadow: 0 16px 44px rgba(20,33,121,.25);
  position: sticky; top: 84px;   /* el aviso queda siempre visible aunque la lista sea larga */
}
.view-lock-box .vl-emoji { font-size: 40px; line-height: 1; margin-bottom: 6px; }
.view-lock-box h3 { font-size: 19px; color: var(--azul); margin-bottom: 8px; }
.view-lock-box p { font-size: 14px; line-height: 1.5; color: var(--tinta); margin-bottom: 14px; }
.view-lock-box .btn { margin-top: 0; display: inline-block; }

/* ---------- Layout con publicidad ---------- */
.layout { display: flex; max-width: 1600px; margin: 0 auto; gap: 16px; }
main { flex: 1; padding: 28px; min-width: 0; }

.ad-side {
  width: 180px;
  padding: 28px 16px 28px 0;
  flex-shrink: 0;
}
.ad-slot {
  border: 2px dashed var(--azul-suave);
  border-radius: var(--radio);
  height: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gris);
  font-size: 12px;
  text-align: center;
  position: sticky;
  top: 80px;
}
.ad-bottom {
  display: none;
  border-top: 2px dashed var(--azul-suave);
  background: var(--blanco);
  text-align: center;
  padding: 14px;
  color: var(--gris);
  font-size: 12px;
  position: sticky;
  bottom: 0;
}

/* ---------- Vistas ---------- */
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

h1 { font-weight: 800; font-size: 34px; line-height: 1.25; }
h2 { font-weight: 800; font-size: 24px; margin-bottom: 12px; }
h3 { font-weight: 600; font-size: 17px; margin-bottom: 8px; }
.sub { color: var(--gris); margin-top: 8px; }

/* ---------- Inicio ---------- */
.hero { text-align: center; padding: 30px 10px 36px; }
.hero-actions { display: flex; gap: 16px; justify-content: center; margin-top: 26px; flex-wrap: wrap; }
/* Héroe de la home: avatar + texto al lado (escritorio) · apilado y compacto (móvil) */
.home-hero { display: flex; align-items: center; justify-content: center; gap: 28px; text-align: left; flex-wrap: wrap; padding: 24px 10px; }
.home-hero-av { width: 200px; height: auto; flex: 0 0 auto; }
.home-hero-text { flex: 1 1 340px; max-width: 560px; }
.home-hero .hero-actions { justify-content: flex-start; }
@media (max-width: 760px) {
  .home-hero { flex-direction: column; text-align: center; gap: 6px; padding: 8px 10px 4px; }
  .home-hero-av { width: 116px; }
  .home-hero .hero-actions { justify-content: center; margin-top: 16px; }
}

.btn-big {
  font-family: inherit;
  font-weight: 800;
  font-size: 18px;
  padding: 16px 34px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  box-shadow: var(--sombra);
}
.btn-big:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(20,33,121,.18); }
.btn-primary { background: var(--azul); color: #fff; }
.btn-accent { background: var(--acento); color: #fff; }

.home-cards { display: flex; gap: 20px; flex-wrap: wrap; }
.card {
  background: var(--blanco);
  border-radius: var(--radio);
  padding: 20px;
  box-shadow: var(--sombra);
  flex: 1;
  min-width: 220px;
}
.card-cyan { background: var(--cyan); color: #142179; }
.card-magenta { background: var(--magenta); color: #142179; }
.card-yellow { background: var(--amarillo); color: #142179; }
.card-cyan h3, .card-magenta h3, .card-yellow h3,
.card-cyan p, .card-magenta p, .card-yellow p { color: #142179; }
.elo-estimate { font-weight: 700; margin-top: 8px; }
.elo-info-btn { font-family: inherit; font-size: 11px; font-weight: 700; cursor: pointer; border: none; background: transparent; color: #142179; text-decoration: underline; padding: 0 2px; white-space: nowrap; }
.elo-info-btn:hover { opacity: .75; }
/* cajita explicativa: aparece ahí mismo, se lee rápido y se cierra sola */
.elo-info { margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: rgba(255,255,255,.72); color: #142179; font-size: 12px; line-height: 1.45; }
.card-impulso { background: #142179; color: #fff; }
body.dark .card-impulso { background: #4F6DFF; }
.card-impulso h3, .card-impulso p { color: #fff; }
/* tarjeta a todo el ancho, debajo de las tres cajas */
.home-impulso {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.home-impulso .impulso-text { flex: 1; min-width: 240px; }
.home-impulso .impulso-text p { margin-top: 6px; }
.card-impulso .btn {
  display: inline-block;
  background: var(--acento);
  color: #fff;
  border: none;
  font-weight: 700;
  white-space: nowrap;
  margin-top: 0;
  flex-shrink: 0;
}
.card-impulso .btn:hover { background: #c81a55; }

.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  background: var(--blanco);
  color: var(--tinta);
  border: 1.5px solid var(--azul-suave);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s;
  margin-top: 6px;
}
.btn:hover { background: var(--casilla-clara); }
.btn.btn-primary { background: var(--azul); color: #fff; border-color: var(--azul); }
.btn.btn-primary:hover { background: #3d59e8; }

/* ---------- Configurar partida ---------- */
.play-setup {
  max-width: 520px;
  margin: 0 auto;
  background: var(--blanco);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 28px;
}
.setup-row { margin: 18px 0; }
.setup-row label { font-weight: 600; display: block; margin-bottom: 8px; }
.setup-row input[type="range"] { width: 56%; vertical-align: middle; accent-color: var(--azul); }
#aiLevelLabel { font-weight: 800; color: var(--azul); margin-left: 10px; white-space: nowrap; }

select {
  font-family: inherit;
  font-size: 14px;
  padding: 8px;
  border-radius: 8px;
  border: 1.5px solid var(--azul-suave);
  width: 100%;
  background: var(--blanco);
  color: var(--tinta);
}

.seg { display: inline-flex; border-radius: 8px; overflow: hidden; border: 1.5px solid var(--azul-suave); }
.segbtn {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border: none;
  background: var(--blanco);
  color: var(--tinta);
  padding: 8px 16px;
  cursor: pointer;
}
.segbtn.active { background: var(--azul); color: #fff; }

/* ---------- Tablero ---------- */
/* Disposición en FILA: tablero a la izquierda, panel a la derecha.
   El tablero ocupa el máximo posible; el panel toma un ancho fijo flexible.
   Solo se apila en vertical (orientación portrait), ver más abajo. */
/* ============================================================
   PATRÓN ÚNICO DE TABLERO ("board stage") — FUENTE ÚNICA DE ESTILO
   Cualquier vista con esta estructura hereda el tamaño/responsive correctos.
   NO reprogramar el layout del tablero por vista; reutilizar estas clases:

     <div class="game-area">                (estadio: tablero + panel, centrado, alto completo)
       <div class="board-wrap">
         <div class="board-col">
           <div class="board-row">          (barra eval · capturadas · tablero · capturadas)
             <div class="eval-wrap"> … </div>
             <div class="cap-side"></div>   (opcional)
             <div class="board-and-arrows"> <div class="board"></div> <svg class="arrows"></svg> </div>
             <div class="cap-side"></div>   (opcional)
           </div>
         </div>
       </div>
       <aside class="coach-panel"> … </aside>  (panel tipo entrenador)
     </div>
   ============================================================ */
.game-area { display: flex; gap: 28px; align-items: center; min-height: calc(100vh - 118px); }
.board-wrap { display: block; flex: 1 1 auto; min-width: 0; }
.board-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
/* fila: barra · capturadas tuyas · TABLERO (crece) · capturadas del rival */
.board-row { display: flex; gap: 10px; align-items: stretch; justify-content: center; container-type: inline-size; }

/* columnas de piezas capturadas a ambos lados del tablero (fuera de él) */
.cap-side {
  display: flex; flex-direction: column; flex-wrap: wrap;
  align-content: flex-start; gap: 2px;
  flex: 0 0 auto;
  width: clamp(30px, 5.5cqw, 48px);
  align-self: stretch;
  overflow: hidden;
}
.cap-side .cap { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.cap-side .cap .piece.glyph { font-size: clamp(24px, 5cqw, 46px); line-height: 1; }
.cap-side .cap .piece.img3d, .cap-side .cap .piece.gaudi { width: 96%; height: 96%; }

/* El tablero CRECE para llenar el ancho disponible de la fila (tras barra y capturadas),
   limitado por la altura de la ventana. Así aprovecha el máximo de pantalla. */
.board-and-arrows { position: relative; margin: 0 auto; }
/* JUGAR: el tablero se rige por la ALTURA del navegador para llenar siempre la pantalla;
   si no cabe a lo ancho, encoge (flex-shrink) manteniéndose cuadrado. */
.game-area .board-and-arrows {
  flex: 0 1 auto;
  width: min(100%, calc(100vh - 118px));   /* lo que sea menor: ancho disponible o ALTO de ventana */
  aspect-ratio: 1;
  margin: 0;
}
#view-learn .board-and-arrows,
#view-puzzles .board-and-arrows {
  width: min(100%, calc(100vh - 230px));
  max-width: 760px;
}

.board {
  display: grid;
  /* minmax(0,1fr) garantiza casillas SIEMPRE iguales, con o sin pieza dentro */
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--sombra);
  user-select: none;
  container-type: inline-size;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  font-size: clamp(24px, 9.2cqw, 78px);
  line-height: 1;
}
.sq.light { background: var(--casilla-clara); }
.sq.dark { background: var(--casilla-oscura); }

.sq .coord {
  position: absolute;
  font-size: clamp(11px, 3.1cqw, 22px);
  font-weight: 800;
  opacity: .9;
  pointer-events: none;
  z-index: 2;
  text-shadow: 0 1px 1px rgba(255,255,255,.45);
}
.sq.dark .coord { text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.sq .coord.file { right: 4px; bottom: 2px; }
.sq .coord.rank { left: 4px; top: 2px; }
/* color de coordenada en contraste con la casilla */
.sq.light .coord { color: var(--casilla-oscura); }
.sq.dark .coord { color: var(--casilla-clara); }

/* piezas SIN captura de eventos: el clic lo recoge la capa .sq-hit, así ninguna
   pieza vecina (sobre todo en 3D) roba el clic de una casilla de destino */
.piece { pointer-events: none; position: relative; z-index: 2; }
/* capa de clic que cubre toda la casilla, por encima de punto/pieza/color.
   Va COPLANAR con su casilla (sin translateZ) para que su proyección coincida
   exactamente con lo que ves: la punta del ratón siempre cuenta en la casilla correcta.
   Como las piezas no capturan eventos, el clic la atraviesa hasta esta capa. */
.sq-hit { position: absolute; inset: 0; z-index: 8; cursor: pointer; }
.piece.glyph { line-height: 1; }
.piece.glyph.w { color: #FCFCFF; text-shadow: 0 0 2px #142179, 0 0 2px #142179, 1px 1px 2px rgba(20,33,121,.85); }
.piece.glyph.b { color: #142179; text-shadow: 0 0 2px rgba(255,255,255,.6); }
.piece.img3d { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 3px rgba(20,33,121,.3)); }
/* piezas Gaudí: imágenes mosaico verticales (≈98×256) → mantener proporción, sin deformar */
.piece.gaudi { display: block; width: auto; height: 100%; object-fit: contain; }
/* DENTRO DEL TABLERO se dimensionan por ancho del tablero (cqw): 1 casilla = 12.5cqw.
   Así nunca se desbordan, sea cual sea el layout (Jugar, Puzzles, Aprender). */
.board .piece.img3d { width: 11.7cqw; height: 11.7cqw; }
.board .piece.gaudi { width: auto; height: 12.2cqw; }

.sq.selected { outline: 3px solid var(--acento); outline-offset: -3px; z-index: 5; }
.sq.lastmove::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(255, 245, 153, 0.4); pointer-events: none;
}
.sq.incheck::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(241,148,138,.6), transparent 70%); pointer-events: none;
}

/* indicador de jugada posible (punto neutro / aro de captura) */
.sq .dot {
  position: absolute;
  width: 26%; height: 26%;
  border-radius: 50%;
  background: rgba(20, 33, 121, 0.28);
  pointer-events: none;
  z-index: 3;
}
.sq.capture-target .dot { width: 90%; height: 90%; background: transparent; border: 5px solid rgba(20,33,121,.3); }

/* CALIDAD: tiñe la casilla COMPLETA (semáforo), igual que el mapa de amenazas */
.sq .qfill {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 1;              /* 100%: el color del semáforo no depende de la casilla */
}
/* respaldo categórico (si no llega color continuo) */
.sq .qfill.q-good { background: #6CCB8E; }
.sq .qfill.q-ok   { background: #F4D35E; }
.sq .qfill.q-bad  { background: #EE8E84; }
/* % de calidad de la jugada */
.sq .qpct {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(10px, 2.7cqw, 18px);
  font-weight: 800;
  color: #142179;
  z-index: 3;
  pointer-events: none;
  text-shadow: 0 1px 1px rgba(255,255,255,.6);
}
.sq.capture-target .qpct { top: 50%; }

/* mapa de amenazas */
.sq .threat {
  position: absolute; inset: 0;
  background: var(--rojo-amenaza);
  pointer-events: none;
  z-index: 1;
}
.sq .threat.t1 { opacity: .3; }
.sq .threat.t2 { opacity: .5; }
.sq .threat.t3 { opacity: .7; }
.sq.hanging-piece { box-shadow: inset 0 0 0 4px var(--rojo-claro); }
/* casilla de pieza que da jaque: marco en color de acento */
.sq.checker { box-shadow: inset 0 0 0 5px #E91E63; z-index: 3; }
.sq.checker::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(233, 30, 99, 0.22); pointer-events: none;
}

/* flechas */
.arrows {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 4;
}

/* parpadeo de casilla (salida/llegada del rival) — bien visible y duradero */
.sq .flash-ov {
  position: absolute; inset: 0;
  background: rgba(255, 193, 7, 0.85);
  box-shadow: inset 0 0 0 4px #E91E63;
  pointer-events: none; z-index: 6;
  animation: flashBlink 1.25s ease;
}
@keyframes flashBlink {
  0% { opacity: 0; } 15% { opacity: 1; } 45% { opacity: .35; }
  65% { opacity: 1; } 100% { opacity: 0; }
}

/* barra de evaluación: relleno que sube/baja según quién va ganando */
.eval-wrap { width: auto; display: flex; position: relative; z-index: 40; flex: 0 0 auto; gap: 4px; }
.eval-cap {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-size: 11px;
  font-weight: 700;
  color: var(--gris);
  white-space: nowrap;
  align-self: center;
  letter-spacing: .3px;
}
.eval-bar {
  position: relative;
  width: 26px;
  border-radius: 8px;
  overflow: visible;
  box-shadow: var(--sombra);
  /* degradado: verde arriba (vas bien) → amarillo → rojo abajo (vas mal) */
  background: linear-gradient(to bottom,
    #2EAD6B 0%, #7DDBA3 28%, #FFE173 50%, #F4A261 72%, #E05A4F 100%);
}
/* marcador + % de tu evaluación actual */
#evalFill {
  position: absolute;
  left: -2px; right: -2px;
  height: 18px;
  display: flex; align-items: center; justify-content: center;
  background: #142179;
  border: 1.5px solid #fff;
  border-radius: 5px;
  bottom: calc(var(--ev, 50) * 1%);
  transform: translateY(50%);
  transition: bottom .4s, left .4s;
  box-shadow: 0 0 4px rgba(0,0,0,.4);
  font-size: 10px; font-weight: 800; color: #fff;
}

/* ---------- Panel del entrenador ---------- */
.coach-panel {
  flex: 0 0 340px;
  width: 340px;
  background: #FFF599;          /* cuadro del entrenador en amarillo */
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 18px;
  align-self: flex-start;       /* altura según contenido, no estirado */
  position: relative;
  z-index: 20;                  /* el tablero 3D no lo tapa */
}
body.dark .coach-panel { background: var(--blanco); }
/* moves-list legible sobre el panel amarillo */
body:not(.dark) .moves-list { background: rgba(255,255,255,0.65); }
.coach-head { display: flex; justify-content: space-between; align-items: center; }
.engine-status { font-size: 11px; color: var(--gris); }

.coach-msg {
  background: var(--cyan);
  color: #142179;
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
  min-height: 64px;
  font-size: 14px;
}
.coach-msg.warn { background: var(--magenta); }
.coach-msg.good { background: #DFF6E9; }

.coach-controls { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.chk { font-size: 14px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.chk input { accent-color: var(--azul); width: 16px; height: 16px; }

.game-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
/* botones del entrenador: acción en acento, 'Nueva partida' en azul de marca */
#undoBtn, #hintBtn, #resignBtn { background: #E91E63; color: #fff; border-color: #E91E63; }
#undoBtn:hover, #hintBtn:hover, #resignBtn:hover { background: #c81a55; }
#undoBtn:disabled, #hintBtn:disabled { opacity: .5; }
#newGameBtn { background: var(--azul); color: #fff; border-color: var(--azul); }
#newGameBtn:hover { filter: brightness(1.12); }

/* bandejas de piezas capturadas, a ambos lados (arriba/abajo) del tablero */
.captray {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 1px;
  min-height: 34px; padding: 4px 8px;
  position: relative; z-index: 10;
}
.captray .cap { display: inline-flex; width: 28px; height: 28px; }
.captray .cap .piece.glyph { font-size: 24px; }
.captray .cap .piece.img3d, .captray .cap .piece.gaudi { width: 26px; height: 26px; }
.captray .capadv { margin-left: 8px; font-weight: 800; font-size: 13px; color: var(--gris); }

.moves-list {
  font-size: 13px;
  max-height: 180px;
  overflow-y: auto;
  background: var(--fondo);
  border-radius: 8px;
  padding: 10px;
  font-weight: 600;
}
.moves-list .mv { display: inline-block; margin-right: 8px; padding: 1px 5px; border-radius: 4px; }
.moves-list .mv.blunder { background: #F8C8C2; color: #922B21; }
.moves-list .mv.mistake { background: #FFF3BF; color: #7D6608; }

/* ---------- Lecciones ---------- */
.lesson-list { margin-top: 18px; }
.lesson-list-items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 16px; }
@media (max-width: 900px) { .lesson-list-items { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .lesson-list-items { grid-template-columns: 1fr; } }
.lesson-group-title { margin-top: 18px; }
.lesson-group-title:first-child { margin-top: 0; }
.lesson-group-title h3 { font-size: 16px; color: var(--azul); text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--casilla-clara); padding-bottom: 6px; }
.lesson-group-title .lg-prog { float: right; color: var(--gris); font-weight: 600; }
.lesson-item.lv-inter { border-left-color: #924AF7; }
.lesson-item.lv-adv { border-left-color: var(--acento); }
.lesson-item.lv-inter.done, .lesson-item.lv-adv.done { border-left-color: var(--verde); }
.lesson-item {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--blanco);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 16px 20px;
  cursor: pointer;
  transition: transform .12s;
  border-left: 8px solid var(--azul);
}
.lesson-item:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(20,33,121,.16); }
.lesson-item.done { border-left-color: var(--verde); }
.lesson-item .lnum {
  font-weight: 800; font-size: 20px; color: var(--azul);
  width: 36px; text-align: center; flex-shrink: 0;
}
.lesson-item.done .lnum { color: var(--verde); }
.lesson-item .ldesc { font-size: 13px; color: var(--gris); }

.lesson-top { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.lesson-area, .puzzle-area { display: flex; gap: 30px; align-items: flex-start; }
.lesson-board-wrap, .puzzle-board-wrap { flex: 1 1 auto; min-width: 0; }
.lesson-side, .puzzle-side { flex: 0 0 380px; width: 380px; }
/* pasos de solo texto: la tarjeta ocupa todo el ancho */
.lesson-area.no-board .lesson-side { flex: 1 1 auto; width: 100%; max-width: 760px; }

.lesson-text {
  background: var(--blanco);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 18px;
  font-size: 15px;
}
.lesson-feedback { margin: 12px 0; min-height: 40px; font-weight: 600; }
.lesson-feedback.ok { color: #2E9E68; }
.lesson-feedback.ko { color: #E66A6A; }
.lesson-nav { display: flex; gap: 12px; align-items: center; }
#lessonStepNum { font-weight: 600; color: var(--gris); font-size: 13px; }

/* ---------- Puzzles ---------- */
.puzzle-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.puzzle-stats { font-weight: 600; color: var(--gris); }
.puzzle-area { margin-top: 12px; }
.puzzle-goal {
  background: var(--amarillo);
  color: #142179;
  border-radius: 8px;
  padding: 12px;
  font-weight: 600;
}
.puzzle-feedback { margin: 12px 0; min-height: 36px; font-weight: 600; }
.puzzle-feedback.ok { color: #2E9E68; }
.puzzle-feedback.ko { color: #E66A6A; }
.puzzle-buttons { display: flex; gap: 8px; margin-bottom: 14px; }
.puzzle-list { display: flex; flex-wrap: wrap; gap: 8px; }
.puzzle-chip {
  width: 38px; height: 38px;
  border-radius: 8px;
  border: 1.5px solid var(--azul-suave);
  background: var(--blanco);
  color: var(--tinta);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
.puzzle-chip.solved { background: var(--verde); color: #14512F; border-color: var(--verde); }
.puzzle-chip.current { outline: 3px solid var(--acento); }

/* ---------- Ajustes ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.settings-grid input[type="range"] { width: 100%; margin-top: 10px; accent-color: var(--azul); }
.about { margin-top: 24px; color: var(--gris); font-size: 13px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(13, 21, 71, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-box {
  background: var(--blanco);
  border-radius: 14px;
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.review-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.review-table td, .review-table th { padding: 5px 8px; text-align: left; border-bottom: 1px solid var(--casilla-clara); }
.review-table .tag { border-radius: 4px; padding: 1px 6px; font-weight: 700; font-size: 11px; }
.tag.blunder { background: #F8C8C2; color: #922B21; }
.tag.mistake { background: #FFF3BF; color: #7D6608; }
.tag.good { background: #DFF6E9; color: #1E7A4C; }

/* ---------- Tipos de tablero (seleccionables en Ajustes) ---------- */
body[data-board="wood"] {
  --casilla-clara: #F0D9B5;
  --casilla-oscura: #B58863;
}
body[data-board="green"] {
  --casilla-clara: #FFFFDD;
  --casilla-oscura: #86A666;
}
body[data-board="marble"] {
  --casilla-clara: #EDEFF2;
  --casilla-oscura: #AEB6C2;
}
/* Minimalista: blanco y negro puro */
body[data-board="minimal"] {
  --casilla-clara: #FFFFFF;
  --casilla-oscura: #111111;
}
/* contraste de piezas de glifo sobre casillas negras */
body[data-board="minimal"] .piece.glyph.b { color: #111; text-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 3px #fff; }
body[data-board="minimal"] .piece.glyph.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 2px #000, 1px 1px 2px #000; }
/* tableros con textura de mármol (imágenes optimizadas) */
body[data-board="marble"] .sq.light,
body[data-board="marble3d"] .sq.light {
  background-image: url("../assets/boards/marble_light.jpg");
  background-size: 200% 200%;
}
body[data-board="marble"] .sq.dark,
body[data-board="marble3d"] .sq.dark {
  background-image: url("../assets/boards/marble_dark.jpg");
  background-size: 200% 200%;
}
/* variar el encuadre por casilla para que no se repita idéntico (efecto losa) */
body[data-board="marble"] .sq[data-sq$="1"], body[data-board="marble"] .sq[data-sq$="3"], body[data-board="marble"] .sq[data-sq$="5"], body[data-board="marble"] .sq[data-sq$="7"],
body[data-board="marble3d"] .sq[data-sq$="1"], body[data-board="marble3d"] .sq[data-sq$="3"], body[data-board="marble3d"] .sq[data-sq$="5"], body[data-board="marble3d"] .sq[data-sq$="7"] { background-position: 0% 0%; }
body[data-board="marble"] .sq[data-sq$="2"], body[data-board="marble"] .sq[data-sq$="4"], body[data-board="marble"] .sq[data-sq$="6"], body[data-board="marble"] .sq[data-sq$="8"],
body[data-board="marble3d"] .sq[data-sq$="2"], body[data-board="marble3d"] .sq[data-sq$="4"], body[data-board="marble3d"] .sq[data-sq$="6"], body[data-board="marble3d"] .sq[data-sq$="8"] { background-position: 100% 100%; }

/* ---------- Tablero Gaudí (mosaico trencadís): imagen de fondo 8×8 ---------- */
body[data-board="gaudi"] { --casilla-clara: #F3E7CF; --casilla-oscura: #5A3A22; }
body[data-board="gaudi"] .board {
  background-image: url("../assets/boards/gaudi.webp");
  background-size: 100% 100%;
}
body[data-board="gaudi"] .sq.light,
body[data-board="gaudi"] .sq.dark { background-color: transparent; }
body[data-board="gaudi"] .sq .coord { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.95), 0 0 2px rgba(0,0,0,.7); }

/* piezas Gaudí: blancas y negras REALES (mosaico claro / oscuro); solo una sombra suave */
.piece.gaudi { filter: drop-shadow(0 2px 3px rgba(0,0,0,.45)); }

/* Variantes 3D: el tablero se inclina y las piezas se mantienen en pie */
body.board3d .board-and-arrows { perspective: 1050px; }
/* ángulo más marcado y realista; la barra/panel tienen mayor z-index y los clics
   los gestiona la capa .sq-hit, así que no hay problemas de solape */
body.board3d .board {
  transform: rotateX(27deg) scale(0.97);
  transform-style: preserve-3d;
  overflow: visible;
  border-radius: 6px;
  box-shadow: 0 24px 34px rgba(20, 33, 121, 0.3);
}
body.board3d .arrows { transform: rotateX(27deg) scale(0.97); }
body.board3d .sq { transform-style: preserve-3d; overflow: visible; }
/* glifos: estirar levemente para simular volumen (poca elevación → sin zonas muertas) */
body.board3d .piece.glyph {
  display: inline-block;
  transform: rotateX(-27deg) scaleY(1.18);
  transform-origin: center 82%;
  filter: drop-shadow(0 5px 4px rgba(20, 33, 121, 0.32));
}
/* piezas 3D (PNG) y Gaudí: enderezarlas sobre la casilla inclinada */
body.board3d .piece.img3d,
body.board3d .piece.gaudi {
  transform: rotateX(-27deg) translateY(-10%) scale(1.06);
  transform-origin: center bottom;
}
body.board3d .piece.img3d { filter: drop-shadow(0 7px 5px rgba(20, 33, 121, 0.38)); }

/* selector visual de tableros en Ajustes */
.board-theme-list { display: flex; flex-wrap: wrap; gap: 10px; }
.board-chip {
  font-family: inherit;
  font-weight: 600;
  font-size: 12px;
  color: var(--tinta);
  background: var(--blanco);
  border: 2px solid var(--azul-suave);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.board-chip.active { border-color: var(--acento); outline: 2px solid var(--acento); }
.board-chip .bprev {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 44px; height: 44px;
  border-radius: 4px;
  overflow: hidden;
}
.board-chip .bprev.p3d { transform: perspective(120px) rotateX(30deg); }
.board-chip .bprev span { width: 100%; height: 100%; }
.board-chip .bprev.bprev-img { background-size: cover; background-position: center; }

/* botón "otra posibilidad de respuesta": discreto, bajo el cuadro azul del entrenador */
.btn-prob {
  width: 100%; margin: 8px 0 14px; font-family: inherit; font-weight: 700; font-size: 13px;
  padding: 8px 10px; cursor: pointer; border-radius: 8px;
  background: #fff; color: var(--azul); border: 1.5px solid var(--azul-suave);
}
.btn-prob:hover { background: var(--azul-suave); }
.btn-prob:disabled { opacity: .5; cursor: default; }

/* "Personalizar tablero y fichas": botón azul complementario que despliega las opciones */
.quick-style { margin-top: 14px; }
.qs-toggle {
  width: 100%; font-family: inherit; font-weight: 800; font-size: 13px;
  background: #A0E8F2; color: #142179; border: none; border-radius: 8px;
  padding: 10px 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.qs-toggle:hover { background: #8BDDEA; }
.qs-toggle.open { border-radius: 8px 8px 0 0; }
.qs-panel {
  border: 1.5px solid #A0E8F2; border-top: none; border-radius: 0 0 8px 8px;
  background: #ECFAFD; padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.qs-panel[hidden] { display: none; }
.qs-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px; font-weight: 600; color: #142179;
}
.qs-row select {
  font-family: inherit; font-size: 13px; padding: 6px 8px; flex: 0 0 58%;
  border: 1.5px solid #9FD9E4; border-radius: 7px; background: #fff; color: #142179; cursor: pointer;
}

/* ---------- Responsive ----------
   Por defecto (cualquier pantalla horizontal) el panel va a la DERECHA.
   En pantallas estrechas reducimos el ancho del panel para que el tablero quepa;
   solo en orientación VERTICAL apilamos el panel debajo del tablero. */
@media (max-width: 1240px) {
  .coach-panel { flex-basis: 300px; width: 300px; }
  .lesson-side, .puzzle-side { flex-basis: 320px; width: 320px; }
}
@media (max-width: 1040px) {
  .ad-side { display: none; }
  .coach-panel { flex-basis: 260px; width: 260px; }
  .lesson-side, .puzzle-side { flex-basis: 280px; width: 280px; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .navbtn { padding: 7px 9px; font-size: 13px; }
  .logo { font-size: 19px; }
  main { padding: 16px; }
}

/* VERTICAL: apilar panel debajo del tablero, todo a lo ancho */
@media (orientation: portrait) and (max-width: 920px) {
  .ad-side { display: none; }
  .ad-bottom { display: block; }
  /* menú en hamburguesa: logo a la izquierda · racha + hamburguesa a la derecha */
  .topbar { flex-wrap: wrap; align-items: center; }
  .logo { order: 0; }
  .streak-wrap { order: 1; margin-left: auto; }
  .nav-burger { display: block; order: 2; }
  .mainnav {
    display: none; order: 3; flex-basis: 100%; flex-direction: column; gap: 2px;
    margin-top: 8px;
  }
  .mainnav.open { display: flex; }
  .mainnav .navbtn { width: 100%; text-align: left; }
  /* Socio (temporal), Acceso, tema e idioma viven DENTRO del menú hamburguesa */
  #memberToggle, #loginBtn, #themeToggle, #langToggle { display: none; order: 4; }
  #mainnav.open ~ #memberToggle,
  #mainnav.open ~ #loginBtn,
  #mainnav.open ~ #themeToggle,
  #mainnav.open ~ #langToggle { display: inline-flex; align-items: center; justify-content: center; flex-basis: 100%; margin-top: 4px; }
  .game-area, .lesson-area, .puzzle-area { flex-direction: column; align-items: stretch; }
  .board-wrap { width: 100%; }
  /* en vertical: barra HORIZONTAL arriba · tus capturadas · tablero · capturadas del rival */
  .board-row, .reto-board-row { flex-direction: column; align-items: center; }
  .board-row .eval-wrap { order: 0; width: 100%; flex-direction: column; align-items: stretch; gap: 4px; }
  .eval-wrap .eval-cap { writing-mode: horizontal-tb; transform: none; text-align: center; }
  .eval-bar { width: 100%; height: 22px;
    background: linear-gradient(to right, #E05A4F 0%, #F4A261 28%, #FFE173 50%, #7DDBA3 72%, #2EAD6B 100%); }
  #evalFill { left: calc(var(--ev, 50) * 1%); right: auto; top: -2px; bottom: -2px; height: auto; width: 22px; transform: translateX(-50%); }
  /* en directo, en vertical: el badge se quita (el punto del menú ya lo indica) y la barra blanco/negro pasa a horizontal */
  .live-overlay { display: none; }
  #view-live .eval-bar { background: linear-gradient(to right, #f5f6f8 0%, #cfd2da 42%, #6c7180 58%, #15171f 100%); }
  #liveEvalFill { left: calc(var(--ev, 50) * 1%); right: auto; top: -2px; bottom: -2px; height: auto; width: 22px; transform: translateX(-50%); }
  .cap-side { flex-direction: row; flex-wrap: wrap; justify-content: center; width: 100%; align-self: auto; min-height: 38px; }
  #capA { order: 1; }            /* tus capturas, entre la barra y el tablero */
  .board-and-arrows { order: 2; }
  #capB { order: 3; }            /* las del rival, debajo */
  #view-play .board-and-arrows { width: min(92vw, calc(100vh - 300px)); }
  #view-learn .board-and-arrows,
  #view-puzzles .board-and-arrows,
  #view-reto .board-and-arrows { width: min(92vw, calc(100vh - 320px)); margin: 0 auto; max-width: 92vw; }
  .cap-side .cap { width: clamp(30px, 9vw, 48px); }
  .coach-panel, .lesson-side, .puzzle-side { flex-basis: auto; width: 100%; }
}

/* ---------- Banner de cookies / consentimiento ---------- */
.cookie-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: var(--tinta); color: #fff;
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap;
  box-shadow: 0 -4px 16px rgba(0,0,0,.25);
}
.cookie-banner p { font-size: 14px; max-width: 720px; margin: 0; }
.cookie-banner a { color: #FFF599; }
.cookie-actions { display: flex; gap: 10px; }
.cookie-banner .btn { margin: 0; }

/* aviso de bloqueador de anuncios */
.adblock-note {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 190;
  background: var(--acento); color: #fff;
  padding: 12px 18px; border-radius: 12px;
  display: flex; gap: 14px; align-items: center; max-width: 92vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); font-size: 14px; font-weight: 600;
}
.adblock-note .btn { margin: 0; background: #fff; color: var(--acento); border: none; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--casilla-clara);
  padding: 18px 24px 28px;
  text-align: center;
  color: var(--gris);
  font-size: 13px;
}
.site-footer a { color: var(--azul); text-decoration: none; margin: 0 8px; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }
.site-footer .foot-impulso { display: block; margin-top: 8px; }
.site-footer .foot-impulso a { color: var(--acento); }

/* ---------- Partida en directo ---------- */
#view-live { position: relative; }
/* badge superpuesto arriba-izquierda: NO ocupa espacio, no baja el tablero */
.live-overlay { position: absolute; top: 0; left: 0; z-index: 6; }
.live-top { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.live-badge {
  background: var(--acento); color: #fff; font-weight: 800; font-size: 12px;
  padding: 4px 10px; border-radius: 999px; letter-spacing: .5px;
  animation: livePulse 1.6s ease-in-out infinite;
}
@keyframes livePulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.home-live { margin: 20px 0; display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; cursor: pointer; background: var(--blanco); }
.home-live .impulso-text { flex: 1; min-width: 240px; }
/* mini-previsualización 2D de la partida en directo */
.home-live .live-preview { width: clamp(150px, 22vw, 230px); flex-shrink: 0; }
/* ---------- Home en móvil: centrar tablero en directo, botones y títulos ---------- */
@media (max-width: 760px) {
  /* "Partida en directo": tablero centrado y ~40% mayor; botón centrado */
  .home-live { flex-direction: column; align-items: center; gap: 14px; }
  .home-live .live-preview { width: 210px; }
  .home-live .impulso-text { flex: 1 1 auto; min-width: 0; width: 100%; }
  .home-live .btn { align-self: center; }
  /* títulos de las tarjetas (Reto del día, Tu progreso, Consejo del día) centrados */
  .home-cards .card h3 { text-align: center; }
  /* sección Impulso: título y CTA centrados (el texto, como está) */
  .home-impulso { flex-direction: column; align-items: stretch; }
  .home-impulso h3 { text-align: center; }
  .home-impulso .btn { align-self: center; }
}
/* forzar SIEMPRE 2D y plano en la previsualización, aunque el tablero global sea 3D */
#livePreviewBoard, body.board3d #livePreviewBoard { transform: none !important; perspective: none !important; }
#livePreviewBoard .piece, body.board3d #livePreviewBoard .piece { transform: none !important; }
#livePreviewBoard .sq { overflow: hidden; }
/* la mini-partida de la portada usa SIEMPRE tablero clásico (sin mosaico Gaudí ni mármol),
   pase lo que pase con la preferencia del usuario; las fichas van forzadas a clásicas en JS */
#livePreviewBoard.board-classic-fixed { background-image: none !important; --casilla-clara: #EAF0FB; --casilla-oscura: #8FA2EE; }
body.dark #livePreviewBoard.board-classic-fixed { --casilla-clara: #C7D2F5; --casilla-oscura: #5B6FD6; }
#livePreviewBoard.board-classic-fixed .sq.light { background: var(--casilla-clara) !important; background-image: none !important; }
#livePreviewBoard.board-classic-fixed .sq.dark  { background: var(--casilla-oscura) !important; background-image: none !important; }
.home-live .btn { background: var(--acento); color: #fff; border: none; font-weight: 700; white-space: nowrap; flex-shrink: 0; }

.live-clocks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.clock {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--fondo); border-radius: 8px; padding: 8px 14px;
  border: 2px solid transparent;
}
.clock.active { border-color: var(--acento); background: var(--blanco); }
.clock-name { font-weight: 600; color: var(--gris); }
.clock-time { font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--tinta); }
.live-status { font-size: 13px; color: var(--gris); font-weight: 600; min-height: 18px; margin-bottom: 8px; }
.live-comment { font-size: 14px; overflow-y: auto; margin-bottom: 10px; }
.live-comment .lc { padding: 5px 8px; border-bottom: 1px solid var(--casilla-clara); }
/* color por bando, compartido por la lista de jugadas y el feed de análisis */
.mvw { color: var(--azul); font-weight: 700; }
.mvb { color: var(--acento); font-weight: 700; }

/* el panel de "En directo" se comporta igual que el del entrenador (altura según contenido).
   El feed de análisis tiene tope de altura y hace scroll (no crece hasta el infinito). */
#view-live .live-comment { max-height: clamp(160px, 42vh, 560px); overflow-y: auto; }

/* barra "quién va ganando" en directo: DEGRADADO blanco (abajo, ventaja blancas)
   → negro (arriba, ventaja negras), con marcador + % en la posición de la evaluación */
#view-live .eval-bar {
  background: linear-gradient(to top, #f5f6f8 0%, #cfd2da 42%, #6c7180 58%, #15171f 100%);
}
#liveEvalFill {
  position: absolute; left: -2px; right: -2px;
  height: 18px; bottom: calc(var(--ev, 50) * 1%);
  transform: translateY(50%);
  background: var(--acento); color: #fff;
  border: 1.5px solid #fff; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
  transition: bottom .4s;
  box-shadow: 0 0 4px rgba(0,0,0,.4);
}


/* ---------- Selector de niveles de puzzles ---------- */
.level-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.level-tab {
  font-family: inherit; font-weight: 700; font-size: 13px;
  border: 2px solid var(--azul-suave); background: var(--blanco); color: var(--tinta);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; display: flex; gap: 6px; align-items: center;
}
.level-tab.active { background: var(--azul); color: #fff; border-color: var(--azul); }
.level-tab.master { border-color: var(--acento); }
.level-tab.master.active { background: var(--acento); border-color: var(--acento); }
.level-tab .tprog { font-size: 11px; opacity: .8; }

.puzzle-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }

/* tarjeta de historia de grandes partidas */
.game-info {
  background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 16px; margin-bottom: 14px; border-left: 8px solid var(--acento);
}
.game-info h3 { margin-bottom: 4px; }
.game-info .gi-meta { font-size: 13px; color: var(--gris); font-weight: 600; margin-bottom: 8px; }
.game-info .gi-hist { font-size: 14px; }
.game-info .gi-result { margin-top: 8px; font-weight: 700; color: var(--azul); font-size: 13px; }

/* selector de piezas (chips con vista previa) */
.piece-theme-list { display: flex; flex-wrap: wrap; gap: 10px; }
.piece-chip {
  font-family: inherit; font-weight: 600; font-size: 12px; color: var(--tinta);
  background: var(--blanco); border: 2px solid var(--azul-suave); border-radius: 8px;
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 84px;
}
.piece-chip.active { border-color: var(--acento); outline: 2px solid var(--acento); }
.piece-chip .pprev {
  width: 56px; height: 56px; border-radius: 6px; background: var(--casilla-clara);
  display: flex; align-items: center; justify-content: center; font-size: 38px; overflow: hidden;
}
.piece-chip .pprev img, .piece-chip .pprev svg { width: 90%; height: 90%; object-fit: contain; }
.piece-chip .pprev .glyph { color: #142179; }
