:root {
  --fondo: #ffffff;
  --texto: #1a1a1b;
  --suave: #787c7e;
  --liña: #d3d6da;
  --borde-chea: #878a8c;
  --tecla: #d3d6da;
  --tecla-texto: #1a1a1b;
  --correcta: #6aaa64;
  --presente: #c9b458;
  --ausente: #787c7e;
  --sobre-cor: #ffffff;
  --dialogo: #ffffff;
  --sombra: 0 4px 23px rgba(0, 0, 0, .2);
  --aviso-fondo: #1a1a1b;
  --aviso-texto: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #121213;
    --texto: #f8f8f8;
    --suave: #818384;
    --liña: #3a3a3c;
    --borde-chea: #565758;
    --tecla: #818384;
    --tecla-texto: #f8f8f8;
    --correcta: #538d4e;
    --presente: #b59f3b;
    --ausente: #3a3a3c;
    --dialogo: #1f1f20;
    --sombra: 0 4px 23px rgba(0, 0, 0, .6);
    --aviso-fondo: #f8f8f8;
    --aviso-texto: #121213;
  }
}
:root[data-theme="dark"] {
  --fondo: #121213; --texto: #f8f8f8; --suave: #818384; --liña: #3a3a3c; --borde-chea: #565758;
  --tecla: #818384; --tecla-texto: #f8f8f8; --correcta: #538d4e; --presente: #b59f3b; --ausente: #3a3a3c;
  --dialogo: #1f1f20; --sombra: 0 4px 23px rgba(0, 0, 0, .6); --aviso-fondo: #f8f8f8; --aviso-texto: #121213;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--fondo);
  color: var(--texto);
  font-family: "Helvetica Neue", Arial, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--liña);
  flex: none;
}
h1 {
  margin: 0;
  font-size: clamp(22px, 7vw, 34px);
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: uppercase;
  white-space: nowrap;
}
h1 span { color: var(--correcta); }
.icona {
  background: none;
  border: 0;
  padding: 6px;
  width: 40px;
  height: 40px;
  color: var(--suave);
  border-radius: 8px;
}
.icona:hover { color: var(--texto); }
.icona svg { width: 100%; height: 100%; }

main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 10px 16px;
}
#taboleiro {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  height: min(420px, 100%);
  aspect-ratio: 5 / 6;
  max-width: 100%;
}
.fila { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.cela {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--liña);
  font-size: clamp(20px, 4.5vh, 32px);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  aspect-ratio: 1;
}
.cela.chea { border-color: var(--borde-chea); animation: pop .1s ease-out; }
.cela.c, .cela.p, .cela.a { color: var(--sobre-cor); border-color: transparent; }
.cela.c { background: var(--correcta); }
.cela.p { background: var(--presente); }
.cela.a { background: var(--ausente); }
.cela.xira { animation: xira .35s ease-in both; }
.fila.tremer { animation: tremer .5s; }
.cela.salta { animation: salta .9s ease both; }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes xira { 0% { transform: rotateX(0); } 50% { transform: rotateX(-90deg); } 100% { transform: rotateX(0); } }
@keyframes tremer {
  10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); }
}
@keyframes salta {
  0%, 20% { transform: translateY(0); } 40% { transform: translateY(-30px); } 50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); } 80% { transform: translateY(2px); } 100% { transform: translateY(0); }
}

#teclado {
  flex: none;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 0 8px 4px;
  user-select: none;
}
.fila-teclas { display: flex; gap: 6px; margin-bottom: 8px; touch-action: manipulation; }
.tecla {
  flex: 1;
  height: 58px;
  border: 0;
  border-radius: 4px;
  background: var(--tecla);
  color: var(--tecla-texto);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tecla.ancha { flex: 1.5; font-size: 12px; }
.tecla svg { width: 24px; height: 24px; }
.tecla.c, .tecla.p, .tecla.a { color: var(--sobre-cor); }
.tecla.c { background: var(--correcta); }
.tecla.p { background: var(--presente); }
.tecla.a { background: var(--ausente); }
@media (min-width: 400px) { .tecla { font-size: 16px; } }
@media (max-height: 600px) { .tecla { height: 46px; } header { height: 48px; } }

#banner-savig {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 auto calc(6px + env(safe-area-inset-bottom));
  padding: 4px 12px;
  border-radius: 6px;
  color: var(--suave);
  font-size: 12px;
  text-decoration: none;
  opacity: .85;
  transition: opacity .2s, background .2s;
}
#banner-savig:hover, #banner-savig:focus-visible { opacity: 1; background: var(--liña); }
#banner-savig[hidden] { display: none; }
#banner-savig img { display: block; height: 30px; width: auto; }
@media (max-width: 360px) { #banner-savig .lema { display: none; } }
@media (max-height: 600px) { #banner-savig img { height: 24px; } #banner-savig { padding: 2px 10px; } }

#avisos {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.aviso {
  background: var(--aviso-fondo);
  color: var(--aviso-texto);
  padding: 12px 16px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
  transition: opacity .3s;
}
.aviso.vai { opacity: 0; }

dialog {
  background: var(--dialogo);
  color: var(--texto);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--sombra);
  padding: 24px 20px 20px;
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
dialog:focus { outline: none; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog[open] { animation: entra .2s ease-out; }
@keyframes entra { from { transform: translateY(20px); opacity: 0; } }
dialog h2 { margin: 0 0 12px; font-size: 18px; text-transform: uppercase; letter-spacing: .04em; text-align: center; }
dialog h3 { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; text-align: center; }
dialog p { margin: 10px 0; line-height: 1.4; }
dialog hr { border: 0; border-top: 1px solid var(--liña); margin: 16px 0; }
dialog a { color: inherit; }
.pechar {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: 0;
  font-size: 28px;
  line-height: 1;
  width: 40px;
  height: 40px;
  color: var(--suave);
}
.nota { color: var(--suave); font-size: 14px; }
.destaque { font-weight: 700; }
.creditos { font-size: 12px; color: var(--suave); margin-top: 16px; }
.exemplo { display: grid; grid-template-columns: repeat(5, 40px); gap: 4px; margin-top: 12px; }
.exemplo .cela { font-size: 22px; }

.boton {
  background: var(--correcta);
  color: #fff;
  border: 0;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 14px 24px;
  font-size: 15px;
  letter-spacing: .04em;
}
#btn-xogar { display: block; width: 100%; margin-top: 4px; }

#resultado { text-align: center; }
#resultado:empty { display: none; }
#resultado .titular { font-size: 22px; font-weight: 800; margin: 0 0 6px; }
#resultado .solucion { text-transform: uppercase; letter-spacing: .1em; font-weight: 800; }
#resultado a { display: inline-block; margin: 4px 0 8px; }
#resultado + h2 { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--liña); }

.cifras { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; }
.cifras strong { display: block; font-size: 30px; font-weight: 400; }
.cifras span { font-size: 12px; }

#distribucion { display: grid; gap: 4px; width: 90%; margin: 0 auto; }
.barra-fila { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.barra-fila b { width: 12px; }
.barra {
  background: var(--ausente);
  color: #fff;
  font-weight: 700;
  text-align: right;
  padding: 2px 8px;
  min-width: 24px;
}
.barra.hoxe { background: var(--correcta); }

#pe-final {
  display: none;
  align-items: center;
  justify-content: space-around;
  gap: 16px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--liña);
}
#pe-final.visible { display: flex; }
#texto-compartir {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px;
  font: 14px/1.3 ui-monospace, monospace;
  background: var(--fondo);
  color: var(--texto);
  border: 1px solid var(--liña);
  border-radius: 4px;
  resize: none;
}
#texto-compartir[hidden] { display: none; }
#texto-compartir.agochado { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; }
.seguinte { text-align: center; }
.seguinte span { display: block; font-size: 13px; font-weight: 700; text-transform: uppercase; }
.seguinte strong { display: block; font-size: 30px; font-weight: 400; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition: none !important; }
}
