/* ============================================================
   Criptograma — la frase en líneas que nunca parten una palabra.
   Cada letra es una casilla: hueco grande arriba (lo que escribe el
   jugador) y el símbolo cifrado pequeño debajo, en Geist Mono. Todo
   el tamaño sale de --cw (lo calcula cryptogram.js para que la palabra
   más larga quepa en una línea).
   ============================================================ */
.cg-host { display: flex; justify-content: center; padding: 4px 0 8px; }
.cg {
  --cw: 36px;
  width: 100%; max-width: 900px;
  display: flex; flex-direction: column; gap: 18px;
}

.cg-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: clamp(18px, 3.2vw, 36px) clamp(10px, 3vw, 36px) clamp(16px, 2.6vw, 28px);
}

.cg-phrase {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start;
  column-gap: calc(var(--cw) * .56);
  row-gap: calc(var(--cw) * .34);
  border-radius: var(--r-sm);
  outline: none;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cg-phrase:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--sel) 35%, transparent); }

.cg-word { display: inline-flex; gap: max(2px, calc(var(--cw) * .08)); flex: none; }

.cg-cell {
  width: var(--cw);
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  touch-action: manipulation;
}
.cg-slot {
  box-sizing: border-box;
  width: 100%; height: calc(var(--cw) * 1.1);
  display: grid; place-items: center;
  font-family: var(--font-ui); font-weight: 600;
  font-size: calc(var(--cw) * .6); line-height: 1;
  color: var(--ink);
  border-bottom: 2px solid var(--line-2);
  border-radius: 6px 6px 2px 2px;
  transition: background-color var(--dur), border-color var(--dur), color var(--dur);
}
.cg-sym {
  margin-top: 3px;
  font-family: var(--font-num); font-weight: 500;
  font-size: max(10px, calc(var(--cw) * .34)); line-height: 1.1;
  color: var(--muted);
  letter-spacing: 0;
}
.cg-punct {
  display: grid; place-items: end center;
  height: calc(var(--cw) * 1.1); min-width: calc(var(--cw) * .3);
  padding-bottom: calc(var(--cw) * .14); box-sizing: border-box;
  font-size: calc(var(--cw) * .6); font-weight: 500; line-height: 1;
  color: var(--ink-2);
}

@media (hover: hover) {
  .cg-cell:hover .cg-slot { background: var(--surface-2); }
}
.cg-cell.is-same .cg-slot { background: var(--sel-weak); border-bottom-color: color-mix(in srgb, var(--sel) 55%, var(--line-2)); }
.cg-cell.is-active .cg-slot {
  background: color-mix(in srgb, var(--sel) 24%, var(--surface));
  border-bottom-color: var(--sel);
  box-shadow: inset 0 0 0 2px var(--sel);
}
.cg-cell.is-active .cg-sym, .cg-cell.is-same .cg-sym { color: var(--sel); }

/* pistas iniciales y letras reveladas: fijas, en tono secundario */
.cg-cell.is-given .cg-slot { color: var(--ink-2); font-weight: 500; border-bottom-style: dotted; }
.cg-cell.is-given { cursor: default; }
.cg-cell.is-revealed .cg-slot { color: var(--sel); }
.cg-cell.is-wrong .cg-slot { color: var(--danger); background: var(--danger-weak); border-bottom-color: var(--danger); }
.cg-cell.is-moved .cg-slot { animation: cg-moved .7s var(--ease); }
@keyframes cg-moved { 0% { background: color-mix(in srgb, var(--present) 35%, transparent); } 100% { background: transparent; } }

.cg-author {
  margin: clamp(16px, 2.4vw, 24px) 0 0; text-align: center;
  font-size: var(--t-sm); color: var(--muted);
}
.cg-author::before { content: "— "; }
.cg-plain {
  margin: clamp(18px, 2.6vw, 28px) auto 0; max-width: 42em; text-align: center;
  font-size: clamp(1.05rem, .95rem + .5vw, 1.3rem); line-height: 1.45; font-weight: 500;
  color: var(--ink); text-wrap: balance;
  animation: cg-fade .5s var(--ease) both;
}
.cg-plain + .cg-author { margin-top: 8px; }
@keyframes cg-fade { from { opacity: 0; transform: translateY(4px); } }

/* resuelto: la rejilla se relaja */
.cg.is-done .cg-cell { cursor: default; }
.cg.is-done .cg-slot { border-bottom-color: color-mix(in srgb, var(--success) 60%, var(--line-2)); background: transparent; }
.cg.is-done .cg-cell.is-given .cg-slot, .cg.is-done .cg-cell.is-revealed .cg-slot { color: var(--ink); }

/* ---------- teclado en pantalla ---------- */
.cg-kb {
  display: flex; flex-direction: column; gap: 6px;
  width: 100%; max-width: 540px; margin: 0 auto;
  user-select: none; -webkit-user-select: none;
}
.cg-kb-row { display: flex; justify-content: center; gap: 5px; }
.cg-key {
  flex: 1 1 0; min-width: 0; max-width: 48px; height: 46px;
  display: inline-grid; place-items: center;
  font: 600 1rem/1 var(--font-ui); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  cursor: pointer; padding: 0;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background var(--dur), color var(--dur), transform .08s;
}
.cg-key svg { width: 22px; height: 22px; }
.cg-key-wide { flex: 1.7 1 0; max-width: 84px; }
.cg-key:hover { background: var(--surface-3); }
.cg-key:active { transform: translateY(1px); background: var(--surface-3); }
.cg-key:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; }
/* letra ya asignada a algún símbolo */
.cg-key.is-used { background: transparent; color: var(--muted); border-color: var(--line); font-weight: 500; }
.cg.is-done .cg-kb { display: none; }

.cg-help-note { margin: 4px 0 0; font-size: var(--t-sm); color: var(--muted); line-height: 1.5; }

/* ---------- tarjeta de victoria: la frase en claro ---------- */
.cg-win-quote { margin: 4px 0 14px; text-align: center; }
.cg-win-quote blockquote { margin: 0; }
.cg-win-quote p { margin: 0; font-size: 1.08rem; line-height: 1.45; font-weight: 500; color: var(--ink); text-wrap: balance; }
.cg-win-quote figcaption { margin-top: 6px; font-size: var(--t-sm); color: var(--muted); }
.cg-win-quote figcaption::before { content: "— "; }

@media (max-width: 640px) {
  .cg { gap: 12px; }
  .cg-card { border-radius: var(--r-md); }
  /* el teclado se queda a mano abajo aunque la frase sea larga */
  .cg-kb {
    position: sticky; bottom: 0; z-index: 5;
    margin: 0 -12px; width: auto; max-width: none;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--line);
  }
  .cg-kb-row { gap: 4px; }
  .cg-key { height: 50px; max-width: none; font-size: 1.05rem; }
  .cg-key-wide { flex: 1.6 1 0; }
}
