:root {
  --rojo: #b03a2e;
  --rojo-osc: #8c2d24;
  --verde: #1e8449;
  --verde-claro: #d4efdf;
  --rojo-claro: #fadbd8;
  --amarillo: #f39c12;
  --fondo: #f4f1ea;
  --tarjeta: #ffffff;
  --texto: #2c2c2c;
  --texto-suave: #6b6b6b;
  --borde: #e0dcd2;
  --sombra: 0 2px 8px rgba(0,0,0,.08);
  --radio: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  background: var(--fondo);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: env(safe-area-inset-bottom); }

/* ---------- Topbar ---------- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--rojo);
  color: #fff;
  box-shadow: var(--sombra);
}
#topbar-titulo { font-weight: 600; flex: 1; text-align: center; font-size: 16px; }
.icon-btn {
  background: rgba(255,255,255,.15);
  border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 26px; line-height: 1; cursor: pointer;
}
.perfil-chip {
  background: rgba(255,255,255,.9);
  color: var(--rojo);
  border: none; border-radius: 20px;
  padding: 6px 12px; font-weight: 700; font-size: 14px; cursor: pointer;
}

/* ---------- Layout ---------- */
#app { max-width: 640px; margin: 0 auto; padding: 18px 16px 40px; }
.pantalla { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1 { font-size: 24px; margin-bottom: 4px; }
h2 { font-size: 20px; margin: 22px 0 10px; }
h3 { font-size: 17px; margin: 16px 0 8px; }
p { margin-bottom: 10px; }
.sub { color: var(--texto-suave); font-size: 15px; }

/* ---------- Botões ---------- */
.btn {
  display: block; width: 100%;
  background: var(--rojo); color: #fff;
  border: none; border-radius: var(--radio);
  padding: 16px; font-size: 18px; font-weight: 600;
  cursor: pointer; text-align: center; margin: 10px 0;
  transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.secundario { background: var(--tarjeta); color: var(--texto); border: 2px solid var(--borde); }
.btn.verde { background: var(--verde); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-fila { display: flex; gap: 10px; }
.btn-fila .btn { margin: 0; }

/* ---------- Cards ---------- */
.tarjeta {
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 16px; margin: 12px 0;
  box-shadow: var(--sombra);
}
.tarjeta.clicable { cursor: pointer; }
.tarjeta.clicable:active { transform: scale(.99); }

/* ---------- Seleção de perfil ---------- */
.perfil-grid { display: grid; gap: 16px; margin-top: 30px; }
.perfil-btn {
  background: var(--tarjeta);
  border: 3px solid var(--borde);
  border-radius: 20px;
  padding: 34px 20px; font-size: 24px; font-weight: 700;
  cursor: pointer; color: var(--texto);
}
.perfil-btn .avatar {
  display: block; width: 64px; height: 64px; border-radius: 50%;
  background: var(--rojo); color: #fff;
  font-size: 30px; line-height: 64px; margin: 0 auto 12px;
}
.perfil-btn.d .avatar { background: #b03a2e; }
.perfil-btn.k .avatar { background: #7d3c98; }

/* ---------- Início ---------- */
.cuenta-atras { text-align: center; padding: 20px; }
.cuenta-atras .dias { font-size: 52px; font-weight: 800; color: var(--rojo); line-height: 1; }
.grupos-resumen { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grupo-mini { text-align: center; padding: 14px; border-radius: var(--radio); }
.grupo-mini .nota { font-size: 28px; font-weight: 800; }
.grupo-mini small { display:block; color: var(--texto-suave); font-size: 13px; margin-top: 4px; }

/* ---------- Cronômetro ---------- */
.cronometro {
  position: sticky; top: 62px; z-index: 5;
  background: var(--tarjeta); border: 1px solid var(--borde);
  border-radius: var(--radio); padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--sombra); margin-bottom: 12px;
}
.cronometro .tiempo { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cronometro.alerta .tiempo { color: var(--rojo); }
.cronometro .prog { font-size: 14px; color: var(--texto-suave); }

/* ---------- Texto de leitura ---------- */
.texto-lectura {
  background: #fffef8;
  border-left: 4px solid var(--amarillo);
  padding: 14px 16px; border-radius: 8px;
  white-space: pre-wrap; font-size: 16.5px; line-height: 1.65;
  margin: 12px 0;
}
.instrucciones-es {
  font-style: italic; color: var(--texto-suave);
  background: #f0ede4; padding: 10px 14px; border-radius: 8px; font-size: 15px;
}

/* ---------- Itens / opções ---------- */
.item { margin: 18px 0; }
.item .enunciado { font-weight: 600; margin-bottom: 10px; }
.opciones { display: grid; gap: 8px; }
.opcion {
  display: flex; align-items: center; gap: 10px;
  border: 2px solid var(--borde); border-radius: 12px;
  padding: 13px 14px; cursor: pointer; background: var(--tarjeta);
  font-size: 16px; text-align: left; width: 100%; color: var(--texto);
}
.opcion .letra {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--fondo); color: var(--texto-suave);
  font-weight: 700; text-align: center; line-height: 28px; font-size: 14px;
}
.opcion.sel { border-color: var(--rojo); background: #fdf0ee; }
.opcion.sel .letra { background: var(--rojo); color: #fff; }
/* Revisão */
.opcion.correcta { border-color: var(--verde); background: var(--verde-claro); }
.opcion.correcta .letra { background: var(--verde); color: #fff; }
.opcion.incorrecta { border-color: var(--rojo); background: var(--rojo-claro); }
.opcion.incorrecta .letra { background: var(--rojo); color: #fff; }
.explicacion {
  margin-top: 10px; padding: 12px 14px; border-radius: 10px;
  background: #eef6ff; border-left: 4px solid #2e86c1; font-size: 15px;
}
.explicacion b { color: #1a5276; }

/* ---------- Player de áudio (escuta) ---------- */
.reproductor {
  background: #eef6ff; border: 1px solid #aed6f1;
  border-radius: 12px; padding: 12px; margin: 10px 0;
}
.reproductor-cab { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-audio {
  background: #2e86c1; color: #fff; border: none;
  border-radius: 20px; padding: 10px 18px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-audio:disabled { opacity: .5; }
.btn-audio-sec {
  background: transparent; border: 1px solid #2e86c1; color: #2e86c1;
  border-radius: 20px; padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.reproductor-estado { font-size: 14px; color: var(--texto-suave); }
.reproductor-trans { margin-top: 10px; font-size: 15px; background: #fff; border-radius: 8px; padding: 10px 12px; }
.reproductor-trans p { margin-bottom: 6px; }

/* Opções em imagem (Tarea 1 da escuta) */
.opciones-img { grid-template-columns: repeat(3, 1fr); }
.opciones-img .opcion { flex-direction: column; gap: 8px; padding: 12px 8px; }
.opcion-img { display: block; width: 100%; }
.opcion-img svg { width: 100%; height: auto; max-height: 90px; }
.enunciados-pool p, .tarjeta > p { font-size: 15px; }

/* ---------- Relacionar ---------- */
.relacionar-textos .tarjeta h3 { margin-top: 0; color: var(--rojo); }
.select-relacionar {
  width: 100%; padding: 12px; font-size: 16px;
  border: 2px solid var(--borde); border-radius: 12px; background: var(--tarjeta); color: var(--texto);
}

/* ---------- Oral ---------- */
.textarea-oral {
  width: 100%; padding: 12px; font-size: 16px; margin-top: 8px;
  border: 2px solid var(--borde); border-radius: 12px; font-family: inherit; resize: vertical;
  background: var(--tarjeta); color: var(--texto);
}
.respuesta-oral { margin: 8px 0; }
.foto-oral {
  background: #fff; border: 1px solid var(--borde); border-radius: 12px;
  padding: 8px; margin: 12px 0; text-align: center;
}
.foto-oral svg { width: 100%; max-width: 420px; height: auto; border-radius: 8px; }
.hilo-conversacion {
  max-height: 320px; overflow-y: auto; background: #f7f4ec;
  border: 1px solid var(--borde); border-radius: 12px; padding: 10px; margin: 10px 0;
}
.linea-cam, .linea-yo { padding: 8px 12px; border-radius: 12px; margin: 6px 0; font-size: 15px; max-width: 88%; }
.linea-cam { background: #eef6ff; border: 1px solid #aed6f1; }
.linea-yo { background: var(--verde-claro); margin-left: auto; }

/* ---------- Escrita ---------- */
.contador {
  text-align: right; font-size: 14px; font-weight: 600; margin-top: 6px;
  color: var(--texto-suave);
}
.contador.ok { color: var(--verde); }
.contador.fuera { color: var(--amarillo); }
.error-item {
  background: #fff5f5; border-left: 3px solid var(--rojo);
  border-radius: 8px; padding: 8px 12px; margin: 6px 0; font-size: 15px;
}
.err-orig { text-decoration: line-through; color: var(--rojo); }
.err-corr { color: var(--verde); font-weight: 600; }

/* ---------- Resultado ---------- */
.veredicto { text-align: center; padding: 24px; border-radius: var(--radio); margin: 12px 0; }
.veredicto.apto { background: var(--verde-claro); }
.veredicto.no-apto { background: var(--rojo-claro); }
.veredicto .grande { font-size: 34px; font-weight: 800; }
.veredicto.apto .grande { color: var(--verde); }
.veredicto.no-apto .grande { color: var(--rojo); }
.barra-nota { height: 12px; background: var(--borde); border-radius: 6px; overflow: hidden; margin: 6px 0; }
.barra-nota > span { display: block; height: 100%; background: var(--verde); }
.barra-nota.bajo > span { background: var(--rojo); }

/* ---------- Avisos ---------- */
.aviso {
  background: #fef9e7; border: 1px solid var(--amarillo);
  border-radius: 10px; padding: 12px 14px; font-size: 15px; margin: 12px 0;
}
.aviso.error { background: var(--rojo-claro); border-color: var(--rojo); }

/* ---------- Loading ---------- */
.cargando {
  position: fixed; inset: 0; background: rgba(244,241,234,.9);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 100; gap: 14px;
}
.spinner {
  width: 44px; height: 44px; border: 4px solid var(--borde);
  border-top-color: var(--rojo); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chip-tarea {
  display: inline-block; background: var(--rojo); color: #fff;
  font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 12px; margin-bottom: 6px;
}
.pie { text-align: center; color: var(--texto-suave); font-size: 13px; margin-top: 30px; }
