/* =============================================================
   Zona de juegos PestHunter — estilos propios de la sección.
   Namespace .pg-*  ·  Usa únicamente tokens del style.css V1.
   NO redefine nada del CSS global. Se carga solo en el portal
   (juego-caza-plagas.html) y en las páginas de juegos.
   ============================================================= */

/* ---------- Portal: grid de tarjetas ---------- */
.pg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  gap: clamp(1rem, 2.5vw, 1.5rem);
  margin-top: clamp(1.25rem, 3vw, 2rem);
}
.pg-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: clamp(1.1rem, 3vw, 1.5rem);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.pg-card__tag {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
}
.pg-card__title { font-size: 1.15rem; font-weight: 600; color: var(--ink); }
.pg-card__text { font-size: 0.92rem; color: var(--ink-soft); margin: 0; max-width: none; }
.pg-card__foot { margin-top: auto; padding-top: 0.75rem; }
.pg-card .btn { width: 100%; justify-content: center; }

/* ---------- Cabecera mínima de cada juego ---------- */
.pg-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
}
.pg-shell {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  /* Espacio inferior generoso: el aviso de cookies del sitio (position: fixed)
     puede aparecer si el visitante aún no ha decidido. Con este relleno el
     juego y sus controles quedan por encima y la página puede desplazarse. */
  padding: clamp(0.9rem, 3vw, 1.5rem) var(--pad-inline) clamp(5rem, 20vh, 11rem);
  display: flex;
  flex-direction: column;
  gap: clamp(0.9rem, 2.5vw, 1.4rem);
  flex: 1;
}
.pg-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}
.pg-brand {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}
.pg-brand strong { color: var(--brand); font-weight: 700; }
.pg-back {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand-dark);
  text-decoration: none;
  white-space: nowrap;
}
.pg-back:hover { text-decoration: underline; }

/* ---------- Zona de juego (común) ---------- */
.pg-stage { display: flex; flex-direction: column; gap: 0.85rem; }
.pg-title { font-size: var(--h2); line-height: 1.15; margin: 0; color: var(--ink); }
.pg-sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

.pg-hud {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.pg-hud__item {
  flex: 1 1 8rem;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-align: center;
}
.pg-hud__item b { color: var(--ink); font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.pg-field {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: min(56vh, 30rem);
  background: linear-gradient(180deg, var(--bg-alt) 0%, var(--bg) 100%);
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pg-field--hunt { aspect-ratio: 4 / 3; max-height: min(52vh, 26rem); }

/* Overlays de inicio / fin */
.pg-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.6rem;
  padding: clamp(1.1rem, 4vw, 2rem);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.pg-overlay[hidden] { display: none; }
.pg-overlay h2 { margin: 0; font-size: 1.35rem; color: var(--ink); }
.pg-overlay p { margin: 0; font-size: 0.95rem; color: var(--ink-soft); max-width: 26rem; }
.pg-overlay .pg-score-big {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.pg-overlay .pg-rank { font-weight: 600; color: var(--ink); }
.pg-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 0.4rem;
}
.pg-btn-row .btn { flex: 0 1 auto; }

/* ---------- Caza la Plaga ---------- */
.pg-pest {
  position: absolute;
  font-size: clamp(2rem, 9vw, 2.6rem);
  line-height: 1;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.16s ease-out;
  filter: drop-shadow(0 3px 4px rgba(15, 30, 24, 0.22));
  cursor: pointer;
  will-change: transform;
}
.pg-pest.is-in { transform: translate(-50%, -50%) scale(1); }
.pg-pest.is-hit {
  transform: translate(-50%, -50%) scale(1.5);
  opacity: 0;
  transition: transform 0.22s ease-out, opacity 0.22s ease-out;
  pointer-events: none;
}
.pg-splash {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 700;
  font-size: 1rem;
  color: var(--brand);
  pointer-events: none;
  animation: pg-float 0.6s ease-out forwards;
}
@keyframes pg-float {
  from { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
  to   { opacity: 0; transform: translate(-50%, -50%) translateY(-34px); }
}
@media (prefers-reduced-motion: reduce) {
  .pg-pest, .pg-pest.is-in, .pg-pest.is-hit { transition-duration: 0.01ms; }
  .pg-splash { animation-duration: 0.01ms; }
}

/* ---------- Plaga Invaders ---------- */
.pg-field--canvas { background: linear-gradient(180deg, var(--bg-alt) 0%, #eef3f0 100%); }
.pg-field--canvas canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.pg-touch {
  display: none;
  gap: 0.5rem;
  margin-top: 0.15rem;
}
.pg-touch__btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 0.9rem 0.4rem;
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--bg-alt);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.pg-touch__btn:active { background: var(--brand-tint); }
.pg-touch__btn--fire {
  flex: 1.4 1 0;
  font-size: 1rem;
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}
.pg-touch__btn--fire:active { background: var(--brand-dark); }

/* Muestra controles táctiles en pantallas con puntero grueso / táctiles */
@media (hover: none) and (pointer: coarse) {
  .pg-touch { display: flex; }
}

/* Foco visible coherente con V1 */
.pg-shell :focus-visible,
.pg-touch__btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.pg-foot {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 480px) {
  .pg-hud__item { flex-basis: 6rem; font-size: 0.85rem; }
  .pg-field { max-height: 66vh; }
}

/* ---------- Misión PestHunter ---------- */
/* Campo un poco más alto y con lienzo propio (dibuja todo el escenario). */
.pg-field--scene { aspect-ratio: 5 / 6; max-height: min(62vh, 32rem); }

/* Botón para silenciar (va dentro del HUD) */
.pg-mute {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.5rem 0.8rem;
  font: inherit; font-size: 0.82rem; font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.pg-mute:hover { border-color: var(--line-strong); }
.pg-mute[aria-pressed="true"] { color: var(--muted); }
.pg-mute .pg-mute__ico { width: 15px; height: 15px; flex: none; }

/* Pad táctil de 5 botones para el juego de plataformas */
.pg-touch--pad { flex-wrap: wrap; gap: 0.4rem; }
.pg-touch--pad .pg-touch__btn { flex: 1 1 3.4rem; padding: 0.85rem 0.4rem; font-size: 1.05rem; }
.pg-touch--pad .pg-touch__btn--jump {
  flex: 1.7 1 6rem;
  color: #fff; background: var(--brand); border-color: var(--brand);
}
.pg-touch--pad .pg-touch__btn--jump:active { background: var(--brand-dark); }

/* Aviso breve de "recurso desperdiciado" u otra pista sobre el lienzo */
.pg-flash {
  position: absolute; left: 50%; top: 0.6rem; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 0.35rem 0.8rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  pointer-events: none; opacity: 0;
  transition: opacity 0.2s ease;
}
.pg-flash.is-on { opacity: 0.96; }
.pg-flash--warn { background: var(--danger); }

/* =============================================================
   Sudoku PestHunter
   Sólo números 1-9 en las celdas. La identidad PestHunter queda
   en el marco (encabezado, botones, tokens), no dentro del tablero.
   ============================================================= */

/* Selector de dificultad */
.sdk-diffs { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sdk-diff {
  flex: 1 1 4.4rem;
  padding: 0.55rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg-alt);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sdk-diff:hover { border-color: var(--ink); }
.sdk-diff[aria-pressed="true"] {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}
.sdk-diff:disabled { opacity: 0.5; cursor: default; }

.sdk-hud { margin-top: 0.1rem; }

.sdk-controls-top { display: flex; gap: 0.5rem; }
.sdk-controls-top .btn { flex: 1 1 auto; justify-content: center; }

/* Tablero */
.sdk-boardwrap {
  position: relative;
  width: 100%;
  max-width: min(30rem, 94vw);
  margin-inline: auto;
}
.sdk-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 3px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.sdk-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  background: var(--bg);
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.08s ease;
}
.sdk-cell:nth-child(9n) { border-right: 0; }
.sdk-cell:nth-child(n + 73) { border-bottom: 0; }
.sdk-cell.b-right { border-right: 3px solid var(--ink); }
.sdk-cell.b-bottom { border-bottom: 3px solid var(--ink); }

.sdk-cell__val {
  font-size: clamp(1.05rem, 5.2vw, 1.55rem);
  font-weight: 500;
  line-height: 1;
  color: var(--brand-dark);
}
.sdk-cell.is-given { background: var(--bg-alt); }
.sdk-cell.is-given .sdk-cell__val { color: var(--ink); font-weight: 700; }
.sdk-cell.is-hint .sdk-cell__val { color: var(--brand); font-weight: 700; }
.sdk-cell.is-error .sdk-cell__val { color: var(--danger); font-weight: 700; }

/* marca de error que NO depende sólo del color */
.sdk-cell.is-error::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 0;
  height: 0;
  border-top: 7px solid var(--danger);
  border-left: 7px solid transparent;
}

/* resaltados de ayuda */
.sdk-cell.is-peer { background: var(--brand-tint); }
.sdk-cell.is-same { background: #d6e7de; }
.sdk-cell.is-same .sdk-cell__val {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}
.sdk-cell.is-sel {
  background: #b9ddca;
  box-shadow: inset 0 0 0 3px var(--brand-dark);
  z-index: 1;
}
.sdk-cell.is-sel .sdk-cell__val { color: var(--brand-dark); }

/* notas / candidatos */
.sdk-cell__notes {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
}
.sdk-cell.has-notes .sdk-cell__notes { display: grid; }
.sdk-cell.has-notes .sdk-cell__val { display: none; }
.sdk-note {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.48rem, 2vw, 0.66rem);
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
}

/* tapa de pausa / generación */
.sdk-cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg-alt);
  border: 2.5px solid var(--ink);
  border-radius: 4px;
}
.sdk-cover[hidden] { display: none; }
.sdk-cover__title { font-weight: 700; color: var(--ink); margin-bottom: 0.6rem; }

/* teclado numérico propio */
.sdk-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  width: 100%;
  max-width: min(30rem, 94vw);
  margin-inline: auto;
}
.sdk-key {
  padding: 0.85rem 0.3rem;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--bg-alt);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sdk-key:hover { border-color: var(--ink); }
.sdk-key:active { background: var(--brand-tint); }
.sdk-key--erase { color: var(--ink-soft); font-size: 1.05rem; }
.sdk-key.is-done { opacity: 0.35; }

/* herramientas: notas + pista */
.sdk-tools { display: flex; gap: 0.5rem; }
.sdk-tool {
  flex: 1 1 0;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg-alt);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sdk-tool:hover { border-color: var(--ink); }
.sdk-tool[aria-pressed="true"] {
  color: #fff;
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}
.sdk-tool:disabled { opacity: 0.4; cursor: not-allowed; }
.sdk-tool__v {
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
  font-weight: 700;
}

/* modales a pantalla completa (reutilizan .pg-overlay, pero fijos) */
.sdk-modal { position: fixed; z-index: 120; }
.sdk-modal[hidden] { display: none; }
.sdk-modal__box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: clamp(1.3rem, 5vw, 2rem);
  width: 100%;
  max-width: 22rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.sdk-modal__box h2 { margin: 0; font-size: 1.3rem; }
.sdk-modal__lead { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }
.sdk-modal__note { margin: 0; font-size: 0.9rem; color: var(--ink-soft); min-height: 1rem; }
.sdk-modal__close {
  align-self: center;
  margin-top: 0.2rem;
  padding: 0.3rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
.sdk-stats {
  list-style: none;
  padding: 0;
  margin: 0.2rem 0;
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-align: left;
}
.sdk-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sdk-badge {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

@media (max-width: 400px) {
  .sdk-diff { flex-basis: 3.4rem; font-size: 0.78rem; padding: 0.5rem 0.35rem; }
  .sdk-key { font-size: 1.05rem; padding: 0.75rem 0.2rem; }
  .sdk-tool { font-size: 0.85rem; padding: 0.65rem 0.4rem; }
}
