/*
  Sistema de diseño base de la plataforma.

  MOBILE-FIRST: todos los estilos base están pensados para pantalla de
  móvil (la mayoría de gente entrará así). Las reglas dentro de
  @media (min-width: ...) SUMAN estilos para pantallas más grandes
  (tablet/escritorio), nunca al revés. Es más fácil "añadir" complejidad
  a partir de una base simple que "quitarla" de un diseño pensado para
  escritorio y luego encogido a la fuerza.
*/

:root {
  /* Paleta: azul principal (confianza, aprendizaje), verde para aciertos,
     rojo para errores, grises neutros para el resto. */
  --color-primary: #2d5fd9;
  --color-primary-dark: #1f45a8;
  --color-primary-light: #eaf0fd;

  --color-success: #1f8a3b;
  --color-success-bg: #e3f6e6;

  --color-danger: #c62828;
  --color-danger-bg: #fdeaea;

  --color-warning: #a15c00;
  --color-warning-bg: #fff2e0;

  --color-text: #1a1d29;
  --color-text-muted: #6b7280;
  --color-border: #e2e5eb;
  --color-bg: #f6f7fb;
  --color-surface: #ffffff;

  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(20, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 24, 40, 0.08);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* En pantallas más grandes, el contenido puede respirar más. */
@media (min-width: 768px) {
  .container {
    max-width: 720px;
    padding: 40px 24px 64px;
  }
}
@media (min-width: 1100px) {
  .container.wide {
    max-width: 960px;
  }
}

/* --- Cabecera / navegación --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--color-text);
}
.topbar .brand span {
  color: var(--color-primary);
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* --- Tarjetas --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

/* --- Tipografía --- */
h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
p.muted, .muted { color: var(--color-text-muted); font-size: 14px; }

/* --- Formularios --- */
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text);
}
.field input, .field textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s ease;
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}
.field textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}
.field .error-text {
  color: var(--color-danger);
  font-size: 13px;
  margin-top: 6px;
  display: none;
}
.field.has-error input, .field.has-error textarea {
  border-color: var(--color-danger);
}
.field.has-error .error-text {
  display: block;
}

/* --- Botones --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s ease, transform 0.05s ease;
  width: 100%;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  width: auto;
  padding: 8px 12px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-auto { width: auto; }

/* Spinner simple para el estado de "cargando" en botones. */
.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-label { opacity: 0.85; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Mensajes de estado (alertas) --- */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: var(--color-danger-bg); color: var(--color-danger); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); }

/* --- Grid de estadísticas del dashboard --- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
@media (min-width: 600px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
}
.stat-box .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-primary-dark);
  display: block;
}
.stat-box .label {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* --- Lista de ejercicios --- */
.exercise-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
  color: inherit;
}
.exercise-list-item:last-child { border-bottom: none; }
.exercise-list-item:hover { color: var(--color-primary); }
.exercise-list-item .badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  white-space: nowrap;
}
.exercise-list-item .badge.done {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* --- Resaltado de corrección palabra por palabra --- */
.diff-box {
  line-height: 2;
  font-size: 15px;
  padding: 14px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.w-equal { background: var(--color-success-bg); color: var(--color-success); padding: 1px 4px; border-radius: 4px; }
.w-wrong { background: var(--color-danger-bg); color: var(--color-danger); padding: 1px 4px; border-radius: 4px; text-decoration: line-through; }
.w-missing { background: var(--color-warning-bg); color: var(--color-warning); padding: 1px 4px; border-radius: 4px; border-bottom: 2px dotted var(--color-warning); }

/* --- Utilidades --- */
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-center { text-align: center; }
.mt-24 { margin-top: 24px; }
.hidden { display: none !important; }
