/* ======================================================
   FALLTEM — Secuencia de colores
   UI unificada con "Cálculo amable"
   SOLO TEMA CLARO
   ====================================================== */

/* ===== Variables de tema ===== */
:root{
  color-scheme: light;
  --fs-base: clamp(18px, 1.05vw + 14px, 22px);
  --space: clamp(12px, 1vw + 8px, 18px);
  --font: "Montserrat", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  /* Neutros (tema claro) */
  --bg:#f3f4f6;
  --fg:#0f172a;
  --muted:#6b7280;
  --card:#ffffff;
  --border:#e5e7eb;
  --focus:#5fcbe0;

  /* Botones secundarios / fab */
  --btn-sec-bg:#1b2325;
  --btn-sec-fg:#ffffff;

  /* Botón principal (verde amable) */
  --btn-primary-bg:#99cd68;
  --btn-primary-fg:#062d0f;

  --ok:#22c55e;
  --bad:#f97373;

  /* Colores de los pads */
  --pad-rojo:#f28b82;
  --pad-verde:#9edc7a;
  --pad-azul:#7ecdf2;
  --pad-amarillo:#f7d774;
}

/* ======================================================
   Base
   ====================================================== */
*{ box-sizing:border-box; }
html,body{ height:100%; }
html{ -webkit-text-size-adjust:100%; text-size-adjust:100%; }

body{
  margin:0;
  background:var(--bg);
  color:var(--fg);
  font-family:var(--font);
  font-size:var(--fs-base);
  line-height:1.65;
  -webkit-tap-highlight-color: transparent;
  padding-bottom:var(--space);
}

.wrap{
  max-width:980px;
  width:min(980px, calc(100% - 2*var(--space)));
  margin:0 auto;
}

/* ======================================================
   Card principal y header
   ====================================================== */

/* Card principal del juego (similar a cálculo/test) */
.juego-card{
  max-width:980px;
  margin:0 auto;
  background:var(--card);
  border-radius:32px;
  padding:clamp(1.8rem, 2.2vw + 1rem, 2.6rem);
  box-shadow:0 22px 50px rgba(15,23,42,.18);
  border:1px solid var(--border);
}

.header{
 max-width:460px;      /* igual que controles / tablero / estado */
  margin:0 auto 1.2rem; /* centrado en la card */
  text-align:left;
}

.header-label{
  margin:0 0 .35rem;
  text-transform:uppercase;
  letter-spacing:.25em;
  font-size:.75rem;
  font-weight:900;
  color:#4d7c0f; /* verde tipo lime-700 */
}

.header h1{
  margin:.3rem 0 .5rem;
  font-size:clamp(2.2rem, 2.2vw + 1.4rem, 3rem);
  letter-spacing:0;
  font-weight:900;
}

.header .intro{
  margin:0;
  max-width:40rem;
  color:var(--muted);
}

/* ======================================================
   Skip link
   ====================================================== */
.skip{
  position:absolute;
  left:-9999px;
  top:auto;
  width:1px;
  height:1px;
  overflow:hidden;
}
.skip:focus{
  left:var(--space);
  top:var(--space);
  width:auto;
  height:auto;
  background:#ffffff;
  color:#000;
  padding:.5rem .75rem;
  border-radius:999px;
  z-index:999;
  box-shadow:0 2px 6px rgba(15,23,42,.25);
}

/* ======================================================
   FABs (ayuda + sonido)
   ====================================================== */
.fab-stack{
  position:fixed;
  top:1rem;
  right:1rem;
  z-index:40;
  display:flex;
  flex-direction:column;
  gap:.6rem;
}
.fab{
  width:40px;
  height:40px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#ffffff;
  color:#111827;
  font-weight:900;
  font-size:1rem;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  box-shadow:0 2px 8px rgba(15,23,42,.18);
  text-shadow:0 1px 1px rgba(0,0,0,.25);
  transition:
    transform .08s ease,
    filter .15s ease,
    box-shadow .15s ease,
    background-color .15s ease;
}
.fab:hover{
  background:#e5f4ff;
  transform:translateY(-1px);
}
.fab:focus-visible{
  outline:3px solid var(--focus);
  outline-offset:2px;
}
.fab[aria-pressed="true"]{
  box-shadow:0 0 0 3px var(--focus),
             0 6px 16px rgba(15,23,42,.35);
}

/* Versión compacta para móvil mientras se juega */
body.fab-compact .fab-stack{
  top:.6rem;
  right:.6rem;
  gap:.45rem;
}
body.fab-compact .fab{
  width:36px;
  height:36px;
  box-shadow:0 2px 6px rgba(0,0,0,.2);
}

/* Evitar scroll de fondo cuando el modal está abierto */
body.no-scroll{
  overflow:hidden;
}

/* ======================================================
   Controles (velocidad + botones)
   ====================================================== */
.controles{
  max-width:460px;          /* mismo ancho que el tablero */
  margin:1.4rem auto 1.4rem;/* centrado horizontal */
  display:grid;
  grid-template-columns:1fr;
  gap:1rem;
}
.control{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  gap:.35rem;
}
.control label{
  font-weight:900;
}

/* Select de velocidad */
select{
  appearance:none;
  -webkit-appearance:none;
  -moz-appearance:none;
  background:var(--card);
  color:var(--fg);
  border:1px solid var(--border);
  border-radius:.9rem;
  padding:.85rem 1rem;
  width:100%;
  font-size:1.05rem;
  background-image:url("data:image/svg+xml;utf8,<svg fill='currentColor' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M5 7l5 5 5-5H5z'/></svg>");
  background-repeat:no-repeat;
  background-position:right .85rem center;
  background-size:1rem 1rem;
}
select:focus-visible{
  outline:2px solid var(--focus);
  outline-offset:2px;
}

/* Controles de acción */
.control--actions{
  display:flex;
  flex-direction:column;
  gap:.8rem;
}

/* ======================================================
   Botones
   ====================================================== */
.btn{
  border:0;
  border-radius:18px;
  cursor:pointer;
  font-weight:900;
  padding:.95rem 1.2rem;
  min-height:48px;
  font-size:1.02rem;
  transition:
    transform .08s ease,
    filter .15s ease,
    box-shadow .15s ease,
    background-color .15s ease;
  display:flex;               /* centrado de texto */
  align-items:center;
  justify-content:center;
}
.btn:hover{
  filter:brightness(1.05);
  transform:translateY(-1px);
}
.btn:active{
  transform:translateY(0);
}
.btn:focus-visible{
  outline:3px solid var(--focus);
  outline-offset:3px;
}

.btn.principal{
  background:var(--btn-primary-bg);
  color:var(--btn-primary-fg);
}
.btn.secundario{
  background:var(--btn-sec-bg);
  color:var(--btn-sec-fg);
}

/* Botón terciario: estilo suave para opciones extra */
.btn.terciario{
  background:transparent;
  color:var(--btn-sec-bg);
  border:1px solid var(--border);
  border-radius:18px;
}
.btn.terciario:hover{
  background:color-mix(in oklab, var(--border) 40%, transparent);
}

/* Asegurar enlaces con clase .btn */
a.btn,
a.btn:link,
a.btn:visited,
a.btn:hover,
a.btn:focus,
a.btn:active{
  text-decoration:none;
  color:inherit;
}

/* ======================================================
   Juego / Tablero
   ====================================================== */
.juego{
  margin-top:.5rem;
}

.tablero{
  max-width:460px;
  margin:1.2rem auto;
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:1rem;
}

/* aseguramos que visualmente quede centrado */
.estado{
  max-width:460px;           /* mismo ancho que controles y tablero */
  margin:0.5rem auto 1.2rem;
  text-align:center;
}

.color{
  position:relative;
  width:100%;
  aspect-ratio:1/1;
  border-radius:24px;
  border:4px solid var(--border);
  box-shadow:
    0 2px 10px rgba(15,23,42,.16) inset,
    0 2px 10px rgba(15,23,42,.18);
  cursor:pointer;
  transition:
    transform .08s ease,
    filter .12s ease,
    box-shadow .12s ease,
    opacity .12s ease;
}

/* Colores base */
.color.rojo{      background:var(--pad-rojo); }
.color.verde{     background:var(--pad-verde); }
.color.azul{      background:var(--pad-azul); }
.color.amarillo{  background:var(--pad-amarillo); }

.color:focus-visible{
  outline:4px solid var(--focus);
  outline-offset:3px;
}

/* Estado activo / reproducción */
.color.activo,
.color.is-play{
  transform:scale(1.06);
  filter:brightness(1.18) saturate(1.1);
  box-shadow:
    0 0 0 6px rgba(255,255,255,.9),
    0 0 16px rgba(15,23,42,.45);
}

/* Cuando hay error, atenuamos el tablero */
.tablero.error .color{
  filter:grayscale(.35) opacity(.85);
}
.tablero.error .color.activo{
  filter:none;
}

/* Progreso */
.progresoBar{
  height:10px;
  background:color-mix(in oklab, var(--border) 80%, transparent);
  border-radius:999px;
  overflow:hidden;
  margin-top:.35rem;
}
#pbFill{
  height:100%;
  width:0%;
  background:var(--btn-primary-bg);
  transition:width .25s ease;
}

#mensaje{
  margin-top:.4rem;
  font-size:.95rem;
  color:var(--muted);
}

/* ======================================================
   Footer / Créditos
   ====================================================== */
.mini-credit{
  margin-top:1.4rem;
  padding-top:.8rem;
  border-top:1px solid var(--border);
  font-size:.85rem;
  color:var(--muted);
  text-align:center;
}
.mini-credit a{
  color:inherit;
  font-weight:700;
}

/* ======================================================
   Modal de ayuda
   ====================================================== */
.modal{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(15,23,42,.55);
  z-index:50;
  padding:1rem;
}
.modal[aria-hidden="false"]{
  display:flex;
  align-items:center;
  justify-content:center;
}
.modal-card{
  background:var(--card);
  color:var(--fg);
  border-radius:16px;
  padding:1.5rem 1.75rem;
  max-width:640px;
  width:100%;
  border:1px solid var(--border);
  box-shadow:0 20px 40px rgba(15,23,42,.32);
  position:relative;
}
.modal-title{
  margin:0 0 .75rem;
  font-size:1.25rem;
  font-weight:900;
}
.modal-card h2{
  margin-top:0;
}
.modal-close{
  position:absolute;
  top:.6rem;
  right:.6rem;
  border:0;
  background:transparent;
  cursor:pointer;
  font-size:1.2rem;
  color:var(--muted);
}
.modal-close:focus-visible{
  outline:2px solid var(--focus);
  outline-offset:2px;
}
.modal-actions{
  margin-top:1rem;
  display:flex;
  justify-content:flex-end;
}

/* Tabs dentro del modal */
.modal-tabs{
  display:flex;
  gap:.5rem;
  border-bottom:1px solid var(--border);
  margin:0 0 1rem;
}
.modal-tab{
  position:relative;
  border:0;
  background:none;
  padding:.4rem .9rem .6rem;
  font-size:.95rem;
  font-weight:800;
  color:var(--muted);
  cursor:pointer;
  border-bottom:3px solid transparent;
}
.modal-tab[aria-selected="true"]{
  color:var(--fg);
  border-color:var(--focus);
}
.modal-tab:focus-visible{
  outline:2px solid var(--focus);
  outline-offset:2px;
}
.modal-panel{
  font-size:.95rem;
  line-height:1.6;
}

/* Forzar ocultar si usan [hidden] por JS */
#aboutModal[hidden]{
  display:none !important;
}

/* ======================================================
   Accesibilidad
   ====================================================== */
.visually-hidden{
  position:absolute !important;
  width:1px !important;
  height:1px !important;
  padding:0 !important;
  margin:-1px !important;
  overflow:hidden !important;
  clip:rect(0,0,0,0) !important;
  white-space:nowrap !important;
  border:0 !important;
}

/* Modo daltónico: símbolos sobre los pads */
[data-colorblind="on"] .color{
  position:relative;
}
[data-colorblind="on"] .color::after{
  content:"";
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:clamp(2.2rem, 6vw, 3rem);
  font-weight:900;
  color:#fff;
  text-shadow:0 0 4px rgba(0,0,0,.9);
  pointer-events:none;
}
[data-colorblind="on"] .color.rojo::after{     content:"▲"; }
[data-colorblind="on"] .color.verde::after{    content:"●"; }
[data-colorblind="on"] .color.azul::after{     content:"■"; }
[data-colorblind="on"] .color.amarillo::after{ content:"◆"; }

/* ======================================================
   Responsive
   ====================================================== */
@media (max-width:640px){
  body{
    font-size:clamp(16px, 4vw, 18px);
  }
  .header{
    margin-top:.75rem;
  }
  .tablero{
    gap:.8rem;
  }
}

/* Siempre respetar [hidden] */
[hidden]{ display:none !important; }
