:root {
  --color-primary:   #ED00A6;
  --color-accent-1:  #429DFF;
  --color-accent-2:  #F3A200;
  --color-accent-3:  #ACFF00;
  --color-accent-4:  #9900FF;
  --color-error:     #E74C3C;
  --color-dark:      #222B34;
  --color-light:     #F5FAFD;
  --color-white:     #FFFFFF;

  --cell-bg: var(--color-white);
  --letter-color:  #000000;
  --letter-shadow: rgba(140, 140, 150, 0.5);
  --letter-select: var(--color-primary);
  --letter-correct: #1E9E46;
  --letter-wrong:  var(--color-error);

  --font-title: 'Muli', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body:  'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-body);
  background: linear-gradient(135deg, #ED00A6 0%, #FFEAF6 100%);
  background-attachment: fixed;
  color: var(--color-dark);
}

h1, h2, h3 { font-family: var(--font-title); margin: 0 0 8px; }

button { font-family: var(--font-body); cursor: pointer; }

/* ---------- Modo dislexia (tipografía y espaciado) ---------- */
body.dyslexia-mode {
  --font-title: 'Comic Sans MS', 'Comic Sans', Verdana, sans-serif;
  --font-body: 'Comic Sans MS', 'Comic Sans', Verdana, sans-serif;
  letter-spacing: 0.02em;
  line-height: 1.6;
}
body.dyslexia-mode .ws-cell,
body.dyslexia-mode .word-list li,
body.dyslexia-mode .instructions-list li,
body.dyslexia-mode .level-btn,
body.dyslexia-mode .btn {
  letter-spacing: 0.05em;
  word-spacing: 0.12em;
}

/* ---------- Layout de pantallas ---------- */
.screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.active { display: flex; }

.card {
  background: var(--color-white);
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  padding: 28px 26px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}
.card--menu { max-width: 520px; }
.card--modal { max-width: 560px; max-height: 85vh; overflow-y: auto; text-align: left; }

.title { font-size: 1.8rem; color: var(--color-dark); }
.title--sm { font-size: 1.4rem; text-align: center; }
.subtitle { margin: 0 0 20px; color: #5a6472; }
.section-label { font-size: 1rem; color: var(--color-accent-4); margin-bottom: 10px; }

/* ---------- Botones ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 13px 18px;
  margin: 8px 0;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent-4));
  color: var(--color-white);
  box-shadow: 0 6px 14px rgba(237, 0, 166, 0.35);
}
.btn-ghost {
  background: var(--color-light);
  color: var(--color-dark);
}
.stack-buttons { display: flex; flex-direction: column; }

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--color-white);
  font-size: 1.3rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  line-height: 1;
}

/* ---------- Selección de nivel (menú) ---------- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.level-btn {
  border: 3px solid transparent;
  border-radius: 14px;
  background: var(--color-light);
  padding: 16px 10px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-dark);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.level-btn.selected {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  background: #fff0fa;
}

/* ---------- Ajustes ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0;
  text-align: left;
}
.setting-row label { font-weight: 700; }
.setting-row input[type="range"] { flex: 1; accent-color: var(--color-primary); }
.switch { width: 20px; height: 20px; accent-color: var(--color-primary); }

/* ---------- Pantalla de juego ---------- */
#screen-game { align-items: stretch; padding: 0; }
#screen-game.active { display: flex; flex-direction: column; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  margin-bottom: 12px;
  color: var(--color-white);
}
.game-info {
  display: flex;
  gap: 16px;
  align-items: center;
  background: rgba(255,255,255,0.15);
  padding: 8px 18px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
}
.game-body {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  align-items: flex-start;
  justify-content: center;
  padding: 0 18px 30px;
}

.ws-grid-wrap {
  overflow-x: auto;
  max-width: 100%;
  padding: 14px;
  background: rgba(255,255,255,0.08);
  border-radius: 18px;
}

.ws-grid {
  display: grid;
  grid-template-columns: repeat(var(--size), var(--cell-size));
  grid-template-rows: repeat(var(--size), var(--cell-size));
  gap: 6px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.ws-cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--cell-bg);
  box-shadow: 2px 2px 6px rgba(0,0,0,0.22), 0 1px 2px rgba(0,0,0,0.12);
  color: var(--letter-color);
  text-shadow: 1px 1px 2px var(--letter-shadow);
  font-weight: 800;
  font-size: calc(var(--cell-size) * 0.42);
  font-family: var(--font-title);
  user-select: none;
  cursor: pointer;
}

.ws-cell.selecting {
  color: var(--letter-select);
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 3px;
}
.ws-cell.tap-anchor {
  animation: tap-anchor-pulse 1s ease-in-out infinite;
}
.ws-cell.correct {
  color: var(--letter-correct);
  text-decoration: none;
  box-shadow: 0 0 0 2px rgba(30,158,70,0.45) inset, 2px 2px 6px rgba(0,0,0,0.22);
}
.ws-cell.wrong {
  color: var(--letter-wrong);
  text-decoration: none;
  animation: cell-shake 0.35s ease;
}
/* Marca no dependiente del color, para distinguir el fallo aunque no se perciba el rojo. */
.ws-cell.wrong::after {
  content: '✕';
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--letter-wrong);
  color: var(--color-white);
  font-size: 10px;
  font-weight: 900;
  line-height: 16px;
  text-align: center;
}
@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes tap-anchor-pulse {
  0%, 100% { box-shadow: 2px 2px 6px rgba(0,0,0,0.22), 0 1px 2px rgba(0,0,0,0.12); }
  50% { box-shadow: 0 0 0 3px rgba(237,0,166,0.4), 2px 2px 6px rgba(0,0,0,0.22); }
}

.word-panel {
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  padding: 16px 20px;
  min-width: 180px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}
.word-list { list-style: none; margin: 0; padding: 0; }
.word-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 6px 0;
  color: var(--color-dark);
  transition: color 0.2s ease;
}
.speak-btn {
  flex-shrink: 0;
  border: none;
  background: var(--color-light);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 0.95rem;
  line-height: 1;
}
.speak-btn:active { transform: scale(0.9); }
.word-list li.found {
  color: var(--letter-correct);
  text-decoration: line-through;
  text-decoration-color: var(--letter-correct);
}

/* ---------- Overlays (instrucciones / pausa / victoria) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 43, 52, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay.hidden { display: none; }

.instructions-list { padding-left: 20px; margin: 0 0 18px; }
.instructions-list li { margin-bottom: 10px; line-height: 1.4; }
.instructions-subtitle { text-align: left; margin-top: 6px; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 8px;
  font-weight: 700;
  color: var(--color-white);
}
.tag-magenta { background: var(--color-primary); }
.tag-green { background: var(--color-accent-3); color: var(--color-dark); }
.tag-red { background: var(--color-error); }

.pause-progress { color: #5a6472; margin-bottom: 16px; }

.victory-stats { text-align: left; margin: 10px 0 18px; }
.victory-stats p { display: flex; justify-content: space-between; margin: 6px 0; }
.record-badge {
  text-align: center;
  background: var(--color-accent-2);
  color: var(--color-dark);
  font-weight: 800;
  padding: 8px;
  border-radius: 10px;
  margin-top: 10px;
}

/* Confeti sencillo */
.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti span {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(600deg); opacity: 0.3; }
}

.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .game-body { flex-direction: column; align-items: center; }
  .word-panel { width: 100%; max-width: 340px; }
  .card { padding: 22px 18px; }
}
@media (max-width: 480px) {
  .level-grid { grid-template-columns: 1fr; }
  .game-info { flex-direction: row; gap: 10px; font-size: 0.78rem; padding: 6px 12px; }
}
