* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --bg-2: #1e1b4b;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #818cf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #0ea5e9;
  --border: #334155;
}

html, body { min-height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border-radius: 1.5rem;
  padding: 2rem;
  box-shadow: 0 25px 50px rgba(0,0,0,.5);
  position: relative;
}

.screen { display: flex; flex-direction: column; gap: 1.25rem; }
.screen[hidden] { display: none; }

h1 {
  font-size: 1.6rem;
  background: linear-gradient(90deg, var(--accent), #c084fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}
h2 { font-size: 1.3rem; text-align: center; }
h2 span { color: var(--accent); }
h3 { font-size: 1.05rem; }

.subtitle { text-align: center; color: var(--muted); font-size: .9rem; }

form { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: .4rem; }
label > span { font-size: .8rem; color: var(--muted); font-weight: 600; }

input {
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}
input:disabled { opacity: .55; cursor: not-allowed; }

.actions { display: flex; gap: .5rem; margin-top: .5rem; }

.btn-primary, .btn-secondary, .btn-warning, .btn-info {
  flex: 1;
  padding: .8rem 1rem;
  border: none;
  border-radius: .6rem;
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  transition: background .2s;
  color: white;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #475569; }
.btn-warning { background: var(--warning); color: #1e293b; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-info { background: var(--info); }
.btn-info:hover:not(:disabled) { background: #0284c7; }
.btn-primary:disabled, .btn-secondary:disabled, .btn-warning:disabled, .btn-info:disabled {
  opacity: .5; cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: .55rem 1rem;
  font-size: .8rem;
  cursor: pointer;
  align-self: center;
  transition: all .2s;
}
.btn-ghost:hover { border-color: var(--danger); color: var(--danger); }

.btn-icon {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .5rem;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
  font-size: 1rem;
  transition: all .2s;
  flex-shrink: 0;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* Branding */
.brand-header {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  max-height: 70px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}
.brand-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  letter-spacing: 0.02em;
}

/* Modo toggle */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .75rem;
}
.switch {
  position: relative;
  display: inline-block;
  width: 2.6rem;
  height: 1.4rem;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--border);
  transition: .25s;
  border-radius: 1.4rem;
}
.slider:before {
  content: "";
  position: absolute;
  height: 1rem;
  width: 1rem;
  left: .2rem;
  bottom: .2rem;
  background-color: white;
  transition: .25s;
  border-radius: 50%;
}
.switch input:checked + .slider { background-color: var(--info); }
.switch input:checked + .slider:before { transform: translateX(1.2rem); }
.mode-label { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.mode-label strong { font-size: .9rem; color: var(--text); }
.mode-label small { font-size: .72rem; color: var(--muted); }

.mode-banner {
  text-align: center;
  background: rgba(14,165,233,.15);
  border: 1px solid rgba(14,165,233,.4);
  color: #7dd3fc;
  padding: .5rem .75rem;
  border-radius: .5rem;
  font-size: .8rem;
  font-weight: 600;
}

/* Botón pronunciación */
.btn-speak {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: .35rem;
  color: var(--muted);
  cursor: pointer;
  padding: .25rem .35rem;
  margin-left: .35rem;
  vertical-align: middle;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-speak svg {
  width: 1em;
  height: 1em;
  fill: currentColor;
  display: block;
}
.btn-speak:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-speak:disabled { opacity: .3; cursor: not-allowed; }
.btn-speak-lg { padding: .45rem .55rem; }
.btn-speak-lg svg { width: 1.4em; height: 1.4em; }

.error {
  padding: .7rem 1rem;
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.4);
  border-radius: .6rem;
  color: #fca5a5;
  font-size: .85rem;
  text-align: center;
}

/* Niveles */
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.level-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .75rem;
  padding: 1rem .75rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.level-card:hover:not(.disabled) { border-color: var(--accent); transform: translateY(-2px); }
.level-card.disabled { opacity: .4; cursor: not-allowed; }
.level-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: .25rem;
  letter-spacing: .5px;
}
.level-count { font-size: .75rem; color: var(--muted); }

/* Juego */
.game-header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.game-info { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.game-level { font-weight: 800; color: var(--accent); font-size: 1rem; }
.game-progress { font-size: .75rem; color: var(--muted); }
.game-score { background: var(--bg); padding: .4rem .7rem; border-radius: .5rem; font-weight: 700; font-size: .85rem; white-space: nowrap; }

.hangman-wrap { display: flex; justify-content: center; }
.hangman-wrap svg { width: 100%; max-width: 200px; height: auto; }
.part { opacity: 0; transition: opacity .3s; stroke: var(--danger); stroke-width: 5; fill: none; stroke-linecap: round; }
.part.fill { fill: var(--danger); }
.part.visible { opacity: 1; }

.clue-box { background: var(--bg); padding: 1rem; border-radius: .75rem; border-left: 4px solid var(--primary); }
.clue-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  margin-bottom: .35rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}
.clue-label-right { display: flex; align-items: center; gap: .35rem; text-transform: none; letter-spacing: 0; }
.clue-text { font-size: .95rem; line-height: 1.5; }

.badge {
  font-size: .6rem;
  padding: .15rem .45rem;
  border-radius: .25rem;
  font-weight: 700;
  background: #7c2d12;
  color: #fdba74;
}

.word { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; min-height: 2.8rem; padding: .5rem 0; }
.letter {
  width: 1.7rem;
  height: 2.4rem;
  border-bottom: 3px solid #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  transition: all .2s;
}
.letter.revealed { border-color: var(--success); color: var(--success); }
.letter.missed { border-color: var(--danger); color: var(--danger); }
.letter.hyphen { border: none; }
.space { width: .45rem; }

.keyboard { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.key {
  aspect-ratio: 1;
  border: none;
  border-radius: .4rem;
  background: var(--border);
  color: var(--text);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  text-transform: uppercase;
  min-height: 2rem;
}
.key:hover:not(:disabled) { background: #475569; }
.key:disabled { cursor: not-allowed; opacity: .5; }
.key.correct { background: var(--success); color: var(--bg); }
.key.wrong { background: var(--danger); color: white; }

.game-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.game-actions > * { flex: 1; min-width: 0; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--panel);
  border-radius: 1rem;
  padding: 1.75rem;
  max-width: 480px;
  width: 100%;
  border: 1px solid var(--border);
  text-align: center;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}
.overlay-card h3 { font-size: 1.15rem; margin-bottom: .5rem; }
.overlay-title-success { color: var(--success); }
.overlay-title-danger { color: var(--danger); }
.overlay-word-row { display: flex; align-items: center; justify-content: center; gap: .5rem; flex-wrap: wrap; }
.overlay-word {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent);
  margin: .4rem 0;
  word-break: break-word;
}
.overlay-meta { font-size: .8rem; color: var(--muted); margin-bottom: 1rem; }
.overlay-info {
  text-align: left;
  background: var(--bg);
  padding: 1rem;
  border-radius: .75rem;
  margin-bottom: 1rem;
  font-size: .85rem;
  line-height: 1.5;
}
.overlay-info p { margin: .35rem 0; }
.overlay-info b { color: var(--accent); }

/* Resultado final */
.result-big { text-align: center; background: var(--bg); border-radius: .75rem; padding: 1.25rem; }
.result-score-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: .25rem;
}
.result-score { font-size: 2.5rem; font-weight: 800; color: var(--accent); }

.ranking-title { text-align: center; font-size: .95rem; color: var(--muted); margin-top: .5rem; }

.ranking-list {
  background: var(--bg);
  border-radius: .75rem;
  max-height: 280px;
  overflow-y: auto;
  padding: .5rem;
}
.ranking-empty { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
.ranking-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .55rem .75rem;
  border-radius: .5rem;
  font-size: .9rem;
  gap: .5rem;
}
.ranking-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.ranking-row.me { background: rgba(99,102,241,.15); border: 1px solid rgba(99,102,241,.4); }
.ranking-rank { font-weight: 800; color: var(--accent); min-width: 2rem; }
.ranking-name { flex: 1; margin-left: .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-score { font-weight: 700; color: var(--success); }

/* Toasts */
.toast-container {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 300;
  pointer-events: none;
  max-width: 90vw;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .7rem 1.1rem;
  border-radius: .6rem;
  font-size: .85rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0,0,0,.4);
  animation: toast-in .25s ease-out;
  max-width: 420px;
  text-align: center;
}
.toast-info { border-color: var(--info); color: #7dd3fc; }
.toast-error { border-color: var(--danger); color: #fca5a5; }
.toast-success { border-color: var(--success); color: #86efac; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}
.modal-card h3 { font-size: 1.1rem; margin-bottom: .5rem; }
.modal-card p { font-size: .9rem; color: var(--muted); margin-bottom: 1.25rem; line-height: 1.5; }
.modal-actions { display: flex; gap: .5rem; }
.modal-actions > * { flex: 1; }


/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Tablets y laptops pequeñas */
@media (max-width: 768px) {
  .app {
    border-radius: 1rem;
    padding: 1.75rem;
  }
}

/* Móviles estándar (≤480px) */
@media (max-width: 480px) {
  body {
    padding: .5rem;
    align-items: flex-start;
  }

  .app {
    padding: 1.25rem;
    border-radius: 1rem;
    margin: .5rem 0;
  }

  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 1rem; }

  .subtitle { font-size: .82rem; }

  .brand-header {
    margin-bottom: 1rem;
    padding-bottom: .75rem;
  }
  .brand-logo { max-height: 50px; }
  .brand-footer {
    font-size: .7rem;
    margin-top: 1rem;
    padding-top: .75rem;
  }

  .screen { gap: 1rem; }

  input {
    padding: .65rem .85rem;
    font-size: .95rem;
  }

  .btn-primary, .btn-secondary, .btn-warning, .btn-info {
    padding: .75rem .85rem;
    font-size: .85rem;
  }

  .actions {
    flex-direction: column;
  }

  .mode-toggle {
    padding: .6rem .75rem;
    gap: .6rem;
  }
  .mode-label strong { font-size: .85rem; }
  .mode-label small { font-size: .68rem; }

  .mode-banner {
    font-size: .75rem;
    padding: .45rem .65rem;
  }

  .levels {
    gap: .5rem;
    grid-template-columns: repeat(2, 1fr);
  }
  .level-card { padding: .85rem .5rem; }
  .level-name { font-size: 1rem; }
  .level-count { font-size: .7rem; }

  .game-header { gap: .35rem; }
  .game-level { font-size: .9rem; }
  .game-progress { font-size: .7rem; }
  .game-score {
    padding: .3rem .55rem;
    font-size: .78rem;
  }
  .btn-icon {
    width: 2rem;
    height: 2rem;
    font-size: .9rem;
  }

  .hangman-wrap svg { max-width: 150px; }

  .clue-box { padding: .75rem; }
  .clue-label { font-size: .6rem; }
  .clue-text { font-size: .85rem; }
  .badge { font-size: .55rem; padding: .12rem .35rem; }

  .word {
    gap: .25rem;
    padding: .35rem 0;
    min-height: 2.2rem;
  }
  .letter {
    width: 1.4rem;
    height: 2rem;
    font-size: 1rem;
  }
  .space { width: .3rem; }

  .keyboard { gap: .22rem; }
  .key {
    font-size: .78rem;
    border-radius: .35rem;
    min-height: 1.9rem;
  }

  .game-actions {
    flex-direction: column;
    gap: .4rem;
  }
  .game-actions > * {
    flex: none;
    width: 100%;
  }

  .overlay { padding: .75rem; }
  .overlay-card {
    padding: 1.25rem;
    max-height: calc(100vh - 1.5rem);
  }
  .overlay-word { font-size: 1.5rem; }
  .overlay-info {
    font-size: .8rem;
    padding: .75rem;
  }
  .overlay-card h3 { font-size: 1.05rem; }

  .result-big { padding: 1rem; }
  .result-score { font-size: 2.1rem; }
  .ranking-list { max-height: 220px; }
  .ranking-row {
    font-size: .82rem;
    padding: .5rem .6rem;
  }
  .ranking-rank { min-width: 1.75rem; }

  .toast-container { top: .75rem; }
  .toast {
    font-size: .8rem;
    padding: .6rem .9rem;
  }

  .modal { padding: .75rem; }
  .modal-card {
    padding: 1.25rem;
    max-height: calc(100vh - 1.5rem);
  }
  .modal-card h3 { font-size: 1rem; }
  .modal-card p { font-size: .85rem; }
}

/* Móviles muy pequeños (≤360px) */
@media (max-width: 360px) {
  .app { padding: 1rem; }

  h1 { font-size: 1.2rem; }
  h2 { font-size: 1.05rem; }

  .brand-logo { max-height: 42px; }

  .levels {
    grid-template-columns: 1fr;
  }

  .letter {
    width: 1.15rem;
    height: 1.8rem;
    font-size: .9rem;
  }

  .keyboard { gap: .18rem; }
  .key {
    font-size: .7rem;
    min-height: 1.75rem;
  }

  .hangman-wrap svg { max-width: 120px; }

  .overlay-word { font-size: 1.3rem; }
  .result-score { font-size: 1.9rem; }
}

/* Móviles en horizontal (landscape) */
@media (max-height: 600px) and (orientation: landscape) {
  body {
    align-items: flex-start;
    padding: .5rem;
  }

  .app {
    padding: 1rem;
    margin: .5rem 0;
  }

  .brand-header { display: none; }

  .hangman-wrap svg { max-width: 110px; }

  .keyboard { gap: .2rem; }

  .screen { gap: .75rem; }
}

/* Dispositivos táctiles: sin delay, sin highlight azul */
@media (hover: none) {
  .key,
  .btn-primary,
  .btn-secondary,
  .btn-warning,
  .btn-info,
  .btn-ghost,
  .btn-icon,
  .btn-speak,
  .level-card {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

/* Accesibilidad: menos animaciones si el usuario lo pide */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}