:root {
  --bg:      #0d0d0f;
  --surface: #16161a;
  --border:  #2a2a32;
  --text:    #e8e6e0;
  --muted:   #6b6a72;
  --accent:  #f0a500;
  --accent2: #e05c00;
  --success: #00cc66;
  --danger:  #ff4d4d;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Nav */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.nav-logo {
  font-family: 'DM Mono', monospace;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.nav-user a {
  color: var(--muted);
  font-size: 0.85rem;
}
.nav-user a:hover { color: var(--danger); }

/* Contenedor */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
}

/* Tarjetas de nivel */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 2rem;
}

.level-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  text-decoration: none;
  display: block;
  color: var(--text);
}

.level-card:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.level-card.locked { cursor: not-allowed; opacity: 0.45; }
.level-card.locked:hover { border-color: var(--border); transform: none; }

.level-card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.level-card-name { font-size: 1.05rem; font-weight: 500; margin-bottom: 0.25rem; }
.level-card-desc { font-size: 0.82rem; color: var(--muted); margin-bottom: 1rem; }

.level-req {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  background: #ffffff0a;
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.gold { color: var(--accent); border-color: #f0a50033; background: #f0a50011; }
.badge.green { color: var(--success); border-color: #00cc6633; background: #00cc6611; }

.level-card.unlocked .badge { opacity: 1; }
.lock-icon { float: right; font-size: 1rem; opacity: 0.4; }

/* Barra de progreso de niveles */
.progress-bar-levels {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 2rem;
  overflow: hidden;
}
.progress-bar-levels-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 2px;
  transition: width 0.6s ease;
}

/* Estadísticas del usuario */
.stats-top {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.stat-card {
  flex: 1;
  min-width: 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}
.stat-card .val {
  font-family: 'DM Mono', monospace;
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--accent);
  line-height: 1;
}
.stat-card .lbl {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* NIVEL — pantalla de ejercicio */
.nivel-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem;
}

.nivel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.nivel-title { font-size: 1.1rem; font-weight: 500; }
.nivel-back { color: var(--muted); font-size: 0.85rem; }

.live-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.live-stat { text-align: center; }
.live-stat .v {
  font-family: 'DM Mono', monospace;
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1;
}
.live-stat .l { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 3px; }

.text-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  font-family: 'DM Mono', monospace;
  font-size: 1.25rem;
  line-height: 2.2;
  letter-spacing: 0.02em;
  min-height: 120px;
  margin-bottom: 1.5rem;
  cursor: text;
  position: relative;
  word-break: break-word;
}

.char.correct { color: var(--success); }
.char.wrong { color: var(--danger); background: #ff4d4d18; border-radius: 3px; }
.char.pending { color: var(--muted); }
.char.cursor { position: relative; }
.char.cursor::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 2px;
  background: var(--accent);
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.hidden-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.prog-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 2px;
  transition: width 0.15s;
  width: 0%;
}

.hint-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.btn-sec {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-sec:hover { border-color: var(--accent); color: var(--accent); }

/* Overlay resultado */
.result-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #0d0d0fee;
  align-items: center;
  justify-content: center;
  z-index: 200;
  flex-direction: column;
  gap: 1rem;
  text-align: center;
  padding: 2rem;
}
.result-overlay.show { display: flex; }
.result-wpm {
  font-family: 'DM Mono', monospace;
  font-size: 5rem;
  font-weight: 500;
  color: var(--accent);
  line-height: 1;
}
.result-label { color: var(--muted); font-size: 0.9rem; letter-spacing: 0.1em; text-transform: uppercase; }
.result-sub { color: var(--text); font-size: 1rem; margin-top: 0.5rem; }
.result-unlock {
  background: #00cc6622;
  border: 1px solid #00cc6644;
  color: var(--success);
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}
.result-actions { display: flex; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; justify-content: center; }
.btn-primary {
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.85; }

/* Teclado visual */
.keyboard { margin-top: 2rem; display: flex; flex-direction: column; gap: 5px; align-items: center; }
.kb-row { display: flex; gap: 5px; }
.key {
  min-width: 38px; height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--muted);
  transition: all 0.08s;
  user-select: none;
}
.key.wide { min-width: 56px; }
.key.space { min-width: 220px; }
.key.active { background: var(--accent); color: #000; border-color: var(--accent); transform: translateY(1px); }
.key.wrong { background: #ff4d4d22; color: var(--danger); border-color: var(--danger); }

/* Page header */
.page-header { margin-bottom: 2rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 500; }
.page-header p { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }

/* Responsive */
@media (max-width: 600px) {
  .container, .nivel-wrap { padding: 1rem; }
  .levels-grid { grid-template-columns: 1fr; }
  .stats-top { gap: 0.75rem; }
  .keyboard { display: none; }
  .text-display { font-size: 1rem; padding: 1.25rem; }
  .result-wpm { font-size: 3.5rem; }
}
